Baseline Widely available
Intl.DateTimeFormat
ãªãã¸ã§ã¯ãã¯ãè¨èªã«å¿ããæ¥ä»ã¨æå»ã®æ¸å¼åãå¯è½ã«ãã¾ãã
const date = new Date(Date.UTC(2020, 11, 20, 3, 23, 16, 738));
// Results below assume UTC timezone - your results may vary
// Specify default date formatting for language (locale)
console.log(new Intl.DateTimeFormat("en-US").format(date));
// Expected output: "12/20/2020"
// Specify default date formatting for language with a fallback language (in this case Indonesian)
console.log(new Intl.DateTimeFormat(["ban", "id"]).format(date));
// Expected output: "20/12/2020"
// Specify date and time format using "style" options (i.e. full, long, medium, short)
console.log(
new Intl.DateTimeFormat("en-GB", {
dateStyle: "full",
timeStyle: "long",
timeZone: "Australia/Sydney",
}).format(date),
);
// Expected output: "Sunday, 20 December 2020 at 14:23:16 GMT+11"
ã³ã³ã¹ãã©ã¯ã¿ã¼
Intl.DateTimeFormat()
æ°ãã DateTimeFormat
ãªãã¸ã§ã¯ããçæãã¾ãã
Intl.DateTimeFormat.supportedLocalesOf()
æå®ããããã±ã¼ã«ã®ãã¡ãå®è¡æã®æ¢å®ã®ãã±ã¼ã«ã«ãã©ã¼ã«ããã¯ããã«å¯¾å¿ããããã®ãé åã«åãã¦è¿ãã¾ãã
Intl.DateTimeFormat.prototype.format()
ãã±ã¼ã«ããã³ãã® DateTimeFormat
ãªãã¸ã§ã¯ãã®æ¸å¼åãªãã·ã§ã³ã«åã£ã¦æ¥ä»ãæ¸å¼åããã²ãã¿ã¼é¢æ°ã§ãã
Intl.DateTimeFormat.prototype.formatToParts()
ãªãã¸ã§ã¯ãã® Array
ãè¿ããããã¯å°ç¨ã®ãã±ã¼ã«ãæèããæ¸å¼ã§ä½¿ç¨ãããã¨ãã§ããé¨åå
ã®æ°å¤æååã表ãã¾ãã
Intl.DateTimeFormat.prototype.resolvedOptions()
ãã±ã¼ã«ãåæ ãã¦ããããããã£ã¨ãªãã¸ã§ã¯ãã®åæåä¸ã«è¨ç®ãããç §åãªãã·ã§ã³ããã£ãæ°ãããªãã¸ã§ã¯ããè¿ãã¾ãã
Intl.DateTimeFormat.prototype.formatRange()
ãã®ã¡ã½ãã㯠2 ã¤ã® Date ãåãåãã DateTimeFormat
ã¤ã³ã¹ã¿ã³ã¹ãçæããéã«æå®ããããã±ã¼ã«ã¨ãªãã·ã§ã³ã«åºã¥ãã¦ãæãç°¡æ½ãªæ¹æ³ã§æ¥ä»ã®ç¯å²ãæ¸å¼åãã¾ãã
Intl.DateTimeFormat.prototype.formatRangeToParts()
ãã®ã¡ã½ãã㯠2 ã¤ã® Date ãåãåããæ¸å¼åãããæ¥ä»ã®ç¯å²ã®åé¨åã表ããã±ã¼ã«åºæã®ãã¼ã¯ã³ãå«ããªãã¸ã§ã¯ãã®é åãè¿ãã¾ãã
åºæ¬çã«ããã±ã¼ã«ãæå®ããã«ä½¿ç¨ããã¨ã DateTimeFormat
ã¯æ¢å®ã®ãã±ã¼ã«ã¨ãªãã·ã§ã³ã使ç¨ãã¾ãã
var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
// toLocaleString without arguments depends on the implementation,
// the default locale, and the default time zone
console.log(new Intl.DateTimeFormat().format(date));
// â "12/19/2012" if run with en-US locale (language) and time zone America/Los_Angeles (UTC-0800)
locales ã®ä½¿ç¨
ãã®ä¾ã§ã¯ããã¼ã«ã©ã¤ãºãããæ¥ä»ã¨æå»ã®å½¢å¼ã®ããªã¨ã¼ã·ã§ã³ã®ä¸é¨ç¤ºãã¦ãã¾ããã¢ããªã±ã¼ã·ã§ã³ã®ã¦ã¼ã¶ã¼ã¤ã³ã¿ã¼ãã§ã¤ã¹ã§ä½¿ç¨ãããè¨èªã®ãã©ã¼ããããåå¾ããã«ã¯ã locales
弿°ã使ç¨ãã¦ããã®è¨èª (ããã³ããããããã¤ãã®ãã©ã¼ã«ããã¯è¨èª) ãæå®ãã¦ãã ããã
var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));
// Results below use the time zone of America/Los_Angeles (UTC-0800, Pacific Standard Time)
// US English uses month-day-year order
console.log(new Intl.DateTimeFormat("en-US").format(date));
// â "12/19/2012"
// British English uses day-month-year order
console.log(new Intl.DateTimeFormat("en-GB").format(date));
// â "19/12/2012"
// Korean uses year-month-day order
console.log(new Intl.DateTimeFormat("ko-KR").format(date));
// â "2012. 12. 19."
// Arabic in most Arabic speaking countries uses real Arabic digits
console.log(new Intl.DateTimeFormat("ar-EG").format(date));
// â "١٩â/١٢â/٢٠١٢"
// for Japanese, applications may want to use the Japanese calendar,
// where 2012 was the year 24 of the Heisei era
console.log(new Intl.DateTimeFormat("ja-JP-u-ca-japanese").format(date));
// â "24/12/19"
// when requesting a language that may not be supported, such as
// Balinese, include a fallback language, in this case Indonesian
console.log(new Intl.DateTimeFormat(["ban", "id"]).format(date));
// â "19/12/2012"
options ã®ä½¿ç¨
æ¥ä»ã¨æå»ã®æ¸å¼ã¯ options
弿°ã使ç¨ãã¦ã«ã¹ã¿ãã¤ãºã§ãã¾ãã
var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0, 200));
// request a weekday along with a long date
var options = {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
};
console.log(new Intl.DateTimeFormat("de-DE", options).format(date));
// â "Donnerstag, 20. Dezember 2012"
// an application may want to use UTC and make that visible
options.timeZone = "UTC";
options.timeZoneName = "short";
console.log(new Intl.DateTimeFormat("en-US", options).format(date));
// â "Thursday, December 20, 2012, GMT"
// sometimes you want to be more precise
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"
// sometimes you want to be very precise
options.fractionalSecondDigits = 3; //number digits for fraction-of-seconds
console.log(new Intl.DateTimeFormat("en-AU", options).format(date));
// â "2:00:00.200 pm AEDT"
// sometimes even the US needs 24-hour time
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"
// to specify options but use the browser's default locale, use 'default'
console.log(new Intl.DateTimeFormat("default", options).format(date));
// â "12/19/2012, 19:00:00"
// sometimes it's helpful to include the period of the day
options = { hour: "numeric", dayPeriod: "short" };
console.log(new Intl.DateTimeFormat("en-US", options).format(date));
// â 10 at night
The used calendar and numbering formats can also be set independently via options
arguments:
var options = { calendar: "chinese", numberingSystem: "arab" };
var dateFormat = new Intl.DateTimeFormat("default", options);
var usedOptions = dateFormat.resolvedOptions();
console.log(usedOptions.calendar);
// â "chinese"
console.log(usedOptions.numberingSystem);
// â "arab"
console.log(usedOptions.timeZone);
// â "America/New_York" (the users default timezone)
ããªãã£ã«
formatjs Intl.DateTimeFormat polyfill
仿§æ¸ ãã©ã¦ã¶ã¼ã®äºææ§ é¢é£æ å ±RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4