2 title: Intl.DateTimeFormat
7 `Intl.DateTimeFormat` is used to format date strings in JavaScript.
15 const date = new Date(2012, 11, 20, 3, 0, 0)
21 const date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0))
27 const date = new Date('2018-04-20T12:00:00Z')
30 Note that JavaScript doesn't "store" timezones in a date object. All these date objects, when expressed via `.toString()` or similar, will show the local timezone of the browser, regardless if you parsed UTC dates.
34 #### Default formatting
37 console.log(new Intl.DateTimeFormat().format(date))
38 // → '12/19/2012' (assuming America/Los_Angeles)
44 console.log(new Intl.DateTimeFormat('en-GB').format(date))
45 // → '19/12/2012' (date-first)
51 console.log(new Intl.DateTimeFormat('en-AU', {
52 timeZone: 'Australia/Sydney'
62 console.log(new Intl.DateTimeFormat('default', {
73 console.log(new Intl.DateTimeFormat('en-US', {
81 To specify options without a locale, use `'default'` as a locale.
87 weekday: 'narrow' | 'short' | 'long',
88 era: 'narrow' | 'short' | 'long',
89 year: 'numeric' | '2-digit',
90 month: 'numeric' | '2-digit' | 'narrow' | 'short' | 'long',
91 day: 'numeric' | '2-digit',
92 hour: 'numeric' | '2-digit',
93 minute: 'numeric' | '2-digit',
94 second: 'numeric' | '2-digit',
95 timeZoneName: 'short' | 'long',
97 // Time zone to express it in
98 timeZone: 'Asia/Shanghai',
99 // Force 12-hour or 24-hour
100 hour12: true | false,
102 // Rarely-used options
103 hourCycle: 'h11' | 'h12' | 'h23' | 'h24',
104 formatMatcher: 'basic' | 'best fit'
111 - <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat>