-2

I want to display a date on the page, and want to show it differently by the language in the browser setting. for example: mm/dd/yyyy (in case of 'en') yyyy/mm/dd(in case of 'ko')

currently I use dayjs and it doesn't really help.

how to customize it?

dfassf
  • 142
  • 10

1 Answers1

0

Use toLocaleDateString with no options:

const event = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));

console.log(event.toLocaleDateString('de-DE'));
console.log(event.toLocaleDateString('ar-EG'));
console.log(event.toLocaleDateString(undefined));

// 19.12.2012
// ١٩‏/١٢‏/٢٠١٢
// 12/19/2012
Christian Fritz
  • 20,641
  • 3
  • 42
  • 71