I want my webpage to display the date and time in a user locale.
It seems to be now Intlsupported by most browsers (see Can I use Intl ). I can quickly get the time zone of the browser using Intl.DateTimeFormat().resolvedOptions().timeZone. I was hoping I could use the date and time using my current language by doing the following:
var date = new Date(2017, 11, 31, 23, 59, 59);
var format = new Intl.DateTimeFormat(
undefined,
{
year: "numeric",
month: "numeric",
day: "numeric",
hour: "numeric",
minute: "numeric",
}
)
console.log(format.format(date))
Run codeHide resultI am using Chrome on Windows. My localization of Windows is set to Czech Republic. My preferred site language is set to “Czech” in Chrome, however the browser itself is configured to use English in English.
12 H, en-us. Chrome , 24 .
, - - - locale, Chrome Intl?