const date = new Date();
// 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('zh-CN', {
year: "2-digit",
month: "2-digit",
day: "2-digit",
hour: "numeric",
minute: "numeric",
second: "numeric",
hour12: false, timeZone: 'Asia/Shanghai' }
).format(date));
// Expected output: "Sunday, 20 December 2020 at 14:23:16 GMT+11"
console.log(new Intl.DateTimeFormat('zh-CN', {
year: "2-digit",
month: "2-digit",
day: "2-digit",
hour: "numeric",
minute: "numeric",
second: "numeric",
hour12: false, timeZone: 'Asia/Shanghai' }
).formatToParts(date));