The Intl.DateTimeFormat.prototype.format property returns a getter function that formats a date according to the locale and formatting options of this Intl.DateTimeFormat object.
dateTimeFormat.format(date)
dateThe function returned by the format getter formats a date into a string according to the locale and formatting options of this Intl.DateTimeFormat object.
format
Use the function returned by the format getter for formatting a single date, here for Serbia:
var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
var dateTimeFormat = new Intl.DateTimeFormat('sr-RS', options);
console.log(dateTimeFormat.format(new Date()));
// → "недеља, 7. април 2013."
format with map
Use the function returned by the format getter for formatting all dates in an array. Note that the function is bound to the Intl.DateTimeFormat from which it was obtained, so it can be passed directly to Array.prototype.map().
var a = [new Date(2012, 08), new Date(2012, 11), new Date(2012, 03)];
var options = { year: 'numeric', month: 'long' };
var dateTimeFormat = new Intl.DateTimeFormat('pt-BR', options);
var formatted = a.map(dateTimeFormat.format);
console.log(formatted.join('; '));
// → "setembro de 2012; dezembro de 2012; abril de 2012"
| Desktop | ||||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
| Basic support | 24 | 12 | 29 | 11 | 15 | 10 |
| Mobile | |||||||
|---|---|---|---|---|---|---|---|
| Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
| Basic support | No | 26 | Yes | 56 | ? | 10 | Yes |
| Server | |
|---|---|
| Node.js | |
| Basic support | ? |
Intl.DateTimeFormatDate.prototype.toLocaleString()Date.prototype.toLocaleDateString()Date.prototype.toLocaleTimeString()
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/format