DateTimeFormat

The declaration of a DateTimeFormat has the form:

new Intl.DateT imeFormat([locales[,options]])

A related function is: Date.prototype.to[Locale]{String|DateString|TimeString}()(8.18.3)

localesOptional. A string with a BCP 47 language tag, or an array of such strings. For the general form and interpretation of the locales argument, see the Intl page. The following Unicode extension keys are allowed:
nuNumbering system. Possible values include: "arab", "arabext", "bali", "beng", "deva", "fullwide", "gujr", "guru", "hanidec", "khmr", "knda", "laoo", "latn", "limb", "mlym", "mong", "mymr", "orya", "tamldec", "telu", "thai", "tibt".
caCalendar. Possible values include: "buddhist", "chinese", "coptic", "ethioaa", "ethiopic", "gregory", "hebrew", "indian", "islamic", "islamicc", "iso8601", "japanese", "persian", "roc".
optionsOptional. An object with some or all of the following properties:
localeMatcherThe locale matching algorithm to use. Possible values are "lookup" and "best fit"; the default is "best fit". For information about this option, see the Intl page.

timeZoneThe time zone to use. The only value implementations must recognize is "UTC"; the default is the runtime's default time zone. Implementations may also recognize the time zone names of the IANA time zone database, such as "Asia/Shanghai", "Asia/Kolkata", "America/New_York".

hour12Whether to use 12-hour time (as opposed to 24-hour time). Possible values are true and false; the default is locale-dependent.

formatMatcherThe format matching algorithm to use. Possible values are "basic" and "best fit"; the default is "best fit". See the following paragraphs for information about the use of this property.


<!DOCTYPE html>
<html>
<body>
<script>
var d = new Date('05-31-1999');
var l10nEN = new Intl.DateTimeFormat("en-US");
var l10nDE = new Intl.DateTimeFormat("de-DE");
console.log(l10nEN.format(d));
console.log(l10nDE.format(d));
console.log(new Intl.DateTimeFormat('en-GB').format(d));
console.log(new Intl.DateTimeFormat('ko-KR').format(d));
console.log(new Intl.DateTimeFormat('ar-EG').format(d));
console.log(new Intl.DateTimeFormat('ja-JP-u-ca-japanese').format(d));
console.log(new Intl.DateTimeFormat(['ban', 'id']).format(d));

var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
console.log(new Intl.DateTimeFormat('de-DE', options).format(d));

options.timeZone = 'UTC';
options.timeZoneName = 'short';
console.log(new Intl.DateTimeFormat('en-US', options).formatToParts(d));
console.log(new Intl.DateTimeFormat().resolvedOptions());

options = { hour: 'numeric', minute: 'numeric', second: 'numeric', timeZoneName: 'short' };
console.log(new Intl.DateTimeFormat('en-AU', options).format(d));

options = { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: false };
console.log(d.toLocaleString('en-US', options));
</script>
</body>
</html>

5/31/1999 31.5.1999 31/05/1999 1999. 5. 31. ٣١‏/٥‏/١٩٩٩ 平成11/5/31 31/5/1999 Montag, 31. Mai 1999 [Object, Object, Object, Object, Object, Object, Object, Object, Object] Object {locale: "en-GB", numberingSystem: "latn", calendar: "gregory", timeZone: "Asia/Kuala_Lumpur", year: "numeric"…} 12:00:00 am GMT+8 5/31/1999, 00:00:00