Why Chrome Date .toLocaleString() seems not to use windows.navigator.language?

Viewed 356

According to the documentation {Date object}.toLocaleString() should use the browser default locale (when not specified).
The default locale is visible with navigator.language.

When my locale is "en-GB" I expect the output format to be DD/MM/YYY.
It is returning MM/DD/YYYY ("en" or "en-US") instead.
If I specify the locale to be "en-GB" the output is as expected.

Why the navigator.locale is not used for the .toLocaleString() ?

Date: 24 November 2021.

window.navigator.language  // default "locale" ?
new Date().toString()
new Date().toLocaleDateString()  // is not using the window.navigator.language
new Date().toLocaleDateString("en-GB")  // ok, this use the right format

enter image description here

1 Answers

As Andreas pointed out in a comment, .toLocaleDateString() seems to have some bugs.

This workaround seems to work:

new Date().toLocaleDateString(window.navigator.language) 
Related