javascript date format

Solutions on MaxInterview for javascript date format by the best coders in the world

showing results for - "javascript date format"
Emilee
29 Feb 2019
1<?php
2  // To change the format of an existing date
3  $old_date_format = "20/03/1999";
4  $new_data_format = date("Y-m-d H:i:s", strtotime($old_date_format));
Klara
07 Aug 2020
1%a - Abbreviated weekday name. (Sun, Mon, ...)
2%A - Full weekday name. (Sunday, Monday, ...)
3%w - Weekday as a decimal number. (0, 1, ..., 6)
4%d - Day of the month as a zero-padded decimal. (01, 02, ..., 31)
5%-d - Day of the month as a decimal number. (1, 2, ..., 30)
6%b - Abbreviated month name. (Jan, Feb, ..., Dec)
7%B - Full month name. (January, February, ...)
8%m - Month as a zero-padded decimal number. (01, 02, ..., 12)
9%-m - Month as a decimal number. (1, 2, ..., 12)
10%y - Year without century as a zero-padded decimal number. (00, 01, ..., 99)
11%-y - Year without century as a decimal number. (0, 1, ..., 99)
12%Y - Year with century as a decimal number. (2013, 2019 etc.)
13%H - Hour (24-hour clock) as a zero-padded decimal number. (00, 01, ..., 23)
14%-H - Hour (24-hour clock) as a decimal number. (0, 1, ..., 23)
15%I - Hour (12-hour clock) as a zero-padded decimal number. (01, 02, ..., 12)
16%-I - Hour (12-hour clock) as a decimal number. (1, 2, ... 12)
17%p - Locale’s AM or PM. (AM, PM)
18%M - Minute as a zero-padded decimal number. (00, 01, ..., 59)
19%-M - Minute as a decimal number. (0, 1, ..., 59)
20%S - Second as a zero-padded decimal number. (00, 01, ..., 59)
21%-S - Second as a decimal number. (0, 1, ..., 59)
22%f - Microsecond as a decimal number, zero-padded on the left.  (000000 - 999999)
23%z - UTC offset in the form +HHMM or -HHMM.  
24%Z - Time zone name. 
25%j - Day of the year as a zero-padded decimal number. (001, 002, ..., 366)
26%-j - Day of the year as a decimal number. (1, 2, ..., 366)
27%U - Week number of the year (Sunday as the first day of the week). All days in a new year preceding the first Sunday are considered to be in week 0. (00, 01, ..., 53)
28%W - Week number of the year (Monday as the first day of the week). All days in a new year preceding the first Monday are considered to be in week 0. (00, 01, ..., 53)
29%c - Locale’s appropriate date and time representation. (Mon Sep 30 07:06:05 2013)
30%x - Locale’s appropriate date representation. (09/30/13)
31%X - Locale’s appropriate time representation. (07:06:05)
32%% - A literal '%' character. (%)
Rafaela
16 Jun 2018
1var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
2var today  = new Date();
3
4console.log(today.toLocaleDateString("en-US")); // 9/17/2016
5console.log(today.toLocaleDateString("en-US", options)); // Saturday, September 17, 2016
6console.log(today.toLocaleDateString("hi-IN", options)); // शनिवार, 17 सितंबर 2016
Luca
04 Oct 2018
1const event = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
2
3const options = {  year: 'numeric', month: 'short', day: 'numeric' };
4
5console.log(event.toLocaleDateString('de-DE', options));
6// expected output: Donnerstag, 20. Dezember 2012
7
8console.log(event.toLocaleDateString('en-US', options));
9// US format 
10
11
12// In case you only want the month
13console.log(event.toLocaleDateString(undefined, { month: 'short'}));
14console.log(event.toLocaleDateString(undefined, { month: 'long'}));
Ffion
02 Apr 2016
1const d = new Date('2010-08-05')
2const ye = new Intl.DateTimeFormat('en', { year: 'numeric' }).format(d)
3const mo = new Intl.DateTimeFormat('en', { month: 'short' }).format(d)
4const da = new Intl.DateTimeFormat('en', { day: '2-digit' }).format(d)
5
6console.log(`${da}-${mo}-${ye}`)
Noah
22 Mar 2016
1Modern JavaScript date utility library https://date-fns.org/
2date-fns provides the most comprehensive, yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
similar questions
queries leading to this page
javascript date format