| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat | [Back] [Original] |
Get to know MDN better
Intl.DateTimeFormat
const date = new Date(Date.UTC(2020, 11, 20, 3, 23, 16, 738));
// UTC -
// Specify default date formatting for language (locale)
console.log(new Intl.DateTimeFormat("en-US").format(date));
// : "12/20/2020"
//
console.log(new Intl.DateTimeFormat(["ban", "id"]).format(date));
// : "20/12/2020"
// "style" : full, long, medium, short
console.log(
new Intl.DateTimeFormat("en-GB", {
dateStyle: "full",
timeStyle: "long",
timeZone: "Australia/Sydney",
}).format(date),
);
// : "Sunday, 20 December 2020 at 14:23:16 GMT+11"
Intl.DateTimeFormat() DateTimeFormat
Intl.DateTimeFormat.prototype Intl.DateTimeFormat
Intl.DateTimeFormat.prototype.constructorIntl.DateTimeFormat Intl.DateTimeFormat
Intl.DateTimeFormat.prototype[Symbol.toStringTag][Symbol.toStringTag] "Intl.DateTimeFormat" Object.prototype.toString()
Intl.DateTimeFormat.prototype.format() DateTimeFormat
Intl.DateTimeFormat.prototype.formatRange() 2 Date DateTimeFormat
Intl.DateTimeFormat.prototype.formatRangeToParts()2 Date
Intl.DateTimeFormat.prototype.formatToParts() (Array)
Intl.DateTimeFormat.prototype.resolvedOptions() DateTimeFormat
const date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
// toLocaleString
//
console.log(new Intl.DateTimeFormat().format(date));
// "12/19/2012" en-US America/Los_Angeles (UTC-0800)
locales ()
const date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
// America/Los_Angeles (UTC-0800, )
// --
console.log(new Intl.DateTimeFormat("en-US").format(date));
// "12/19/2012"
// --
console.log(new Intl.DateTimeFormat("en-GB").format(date));
// "19/12/2012"
// --
console.log(new Intl.DateTimeFormat("ko-KR").format(date));
// "2012. 12. 19."
//
console.log(new Intl.DateTimeFormat("ar-EG").format(date));
// "//"
// 2012 24
console.log(new Intl.DateTimeFormat("ja-JP-u-ca-japanese").format(date));
// "24/12/19"
//
console.log(new Intl.DateTimeFormat(["ban", "id"]).format(date));
// "19/12/2012"
options
const date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0, 200));
//
let options = {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
};
console.log(new Intl.DateTimeFormat("de-DE", options).format(date));
// "Donnerstag, 20. Dezember 2012"
// UTC
options.timeZone = "UTC";
options.timeZoneName = "short";
console.log(new Intl.DateTimeFormat("en-US", options).format(date));
// "Thursday, December 20, 2012, GMT"
//
options = {
hour: "numeric",
minute: "numeric",
second: "numeric",
timeZone: "Australia/Sydney",
timeZoneName: "short",
};
console.log(new Intl.DateTimeFormat("en-AU", options).format(date));
// "2:00:00 pm AEDT"
//
options.fractionalSecondDigits = 3; //
console.log(new Intl.DateTimeFormat("en-AU", options).format(date));
// "2:00:00.200 pm AEDT"
// 24
options = {
year: "numeric",
month: "numeric",
day: "numeric",
hour: "numeric",
minute: "numeric",
second: "numeric",
hour12: false,
timeZone: "America/Los_Angeles",
};
console.log(new Intl.DateTimeFormat("en-US", options).format(date));
// "12/19/2012, 19:00:00"
// undefined
console.log(new Intl.DateTimeFormat(undefined, options).format(date));
// "12/19/2012, 19:00:00"
//
options = { hour: "numeric", dayPeriod: "short" };
console.log(new Intl.DateTimeFormat("en-US", options).format(date));
// 10 at night
options
const options = { calendar: "chinese", numberingSystem: "arab" };
const dateFormat = new Intl.DateTimeFormat(undefined, options);
const usedOptions = dateFormat.resolvedOptions();
console.log(usedOptions.calendar);
// "chinese"
console.log(usedOptions.numberingSystem);
// "arab"
console.log(usedOptions.timeZone);
// "America/New_York"
| ECMAScript 2027 Internationalization API Specification # datetimeformat-objects |
Intl.DateTimeFormat (FormatJS)IntlDate.prototype.toLocaleString()Date.prototype.toLocaleDateString()Date.prototype.toLocaleTimeString()Temporal.Instant.prototype.toLocaleString()Temporal.PlainDate.prototype.toLocaleString()Temporal.PlainDateTime.prototype.toLocaleString()Temporal.PlainTime.prototype.toLocaleString()Temporal.PlainYearMonth.prototype.toLocaleString()Temporal.PlainMonthDay.prototype.toLocaleString()Temporal.ZonedDateTime.prototype.toLocaleString()| Web Proxy Viewer | New URL | Original Page |