Intl - patrickcole/learning GitHub Wiki

Intl

Intl.prototype.DateTimeFormat

// timeStyle
// ---------
// short
new Intl.DateTimeFormat("en" , { timeStyle: "short" }).format(Date.now())
// "2:45 PM"

// medium
new Intl.DateTimeFormat("en" , { timeStyle: "medium" }).format(Date.now())
// "2:45:53 PM"

// long
new Intl.DateTimeFormat("en" , { timeStyle: "long" }).format(Date.now())
// "2:46:05 PM GMT+7"

// dateStyle
// ---------
// short
new Intl.DateTimeFormat("en" , { dateStyle: "short" }).format(Date.now())
// "7/25/20"

// medium
new Intl.DateTimeFormat("en" , { dateStyle: "medium" }).format(Date.now())
// "Jul 25, 2020"

// long
new Intl.DateTimeFormat("en" , { dateStyle: "long" }).format(Date.now())
// "July 25, 2020"

Intl.prototype.ListFormat

const options = ['A', 'B', 'C'];

console.log(new Intl.ListFormat('en-US', { style: 'long', type: 'conjunction' }).format(options));
// A, B and C

console.log(new Intl.ListFormat('en-US', { style: 'short', type: 'disjunction' }).format(options));
// A, B or C