PJCHENder 未整理筆記

[WebAPIs] Intl

2019-04-30

[WebAPIs] Intl

@(JavaScript)[JavaScript, WebAPIs]

keywords: Intl, Intl.ListFormat, Intl.DateTimeFormat, Intl.NumberFormat
1
2
// Intl.NumberFormat
new Intl.NumberFormat('en').format(1000) // 1,000
1
2
3
4
5
6
7
// Intl.DataTimeFormat
function ISOtoLongDate(isoString, locale = "en-US") {
const options = { month: "long", day: "numeric", year: "numeric" };
const date = new Date(isoString);
const longDate = new Intl.DateTimeFormat(locale, options).format(date);
return longDate;
}
Tags: WebAPIs

掃描二維條碼,分享此文章