New Options For Intl.DateTimeFormat�3 PRs in ECMA-402: PR 345, 346, 347
New Options for Intl.DateTimeFormat
Format Quarter�ecma402/pull/345
quarter: “short”, “long”, “narrow”
let d = new Date(); �var dtf = new Intl.DateTimeFormat("en", � {year: "numeric", quarter: "short"}); �dtf.format(d); // "Q2 2019" �dtf = new Intl.DateTimeFormat("en", � {year: "numeric", quarter: "long"}); �dtf.format(d); // "2nd quarter 2019"�dtf = new Intl.DateTimeFormat("zh-Hant", � {year: "numeric", quarter: "short"}); �dtf.format(d); // "2019年第2季"
quarter: “short”, “long”, “narrow”
let d = new Date(); �var dtf = new Intl.DateTimeFormat("en", � {year: "numeric", quarter: "short"}); �dtf.formatToParts(d);
// [{type: "quarter", value: "Q2"}, �// {type: "literal", value: " "}, �// {type: "year", value: "2019"}]
Format Day Period
dayPeriod: “short”, “long”, “narrow”
var dtf = new Intl.DateTimeFormat(� "en", {hour: "numeric", dayPeriod: "short"});
�dtf.format(new Date("2019-05-20T07:00")); �// "7 in the morning"�dtf.format(new Date("2019-05-20T12:00")); �// "12 noon"
dayPeriod: “short”, “long”, “narrow”
dtf.format(new Date("2019-05-20T13:00")); �// "1 in the afternoon" �dtf.format(new Date("2019-05-20T18:00")); �// "6 in the evening" �dtf.format(new Date("2019-05-20T22:00:00")); �// "10 at night"
dayPeriod: “short”, “long”, “narrow”
var dtf = new Intl.DateTimeFormat("zh-Hant",� {hour: "numeric", dayPeriod: "short"});��dtf.format(new Date("2019-05-20T11:00")); �// "上午11時" �dtf.format(new Date("2019-05-20T12:00")); �// "中午12時" �dtf.format(new Date("2019-05-20T13:00")); �// "下午1時"
dayPeriod: “short”, “long”, “narrow”
dtf.format(new Date("2019-05-20T18:00")); �// "下午6時" �dtf.format(new Date("2019-05-20T22:00")); �// "晚上10時"
Format Fractional Second�ecma402/pull/347�[Updated 6/5/2019]
millisfractionalSecondDigits: 0 - 3
let t = new Date("2019-05-20T07:00:23.123");�var dtf = new Intl.DateTimeFormat("en",� {second: "numeric", � millisfractionalSecondDigits: 3});�dtf.format(t); // "7:00:23.123 AM" �dtf = new Intl.DateTimeFormat("en",� {second: "numeric",� millisfractionalSecondDigits: 1});�dtf.format(t); // "7:00:23.1 AM" �
When calling to formatToParts
dtf.formatToParts(t);�// [{type: "hour", value: "7"}, �// {type: "literal", value: ":"}, �// {type: "minute", value: "00"}, �// {type: "literal", value: ":"}, �// {type: "second", value: "23"},�// {type: "literal", value: "."}, �// {type: "fractionalSecond", value: "1"}, �// {type: "literal", value: " "}, �// {type: "dayPeriod", value: "AM"}]