Join the AMA (Ask Me Anything) with the Firefox leadership team to celebrate Firefox 20th anniversary and discuss Firefox’s future on Mozilla Connect. Mark your calendar on Thursday, November 14, 18:00 - 20:00 UTC!

Hilfe durchsuchen

Vorsicht vor Support-Betrug: Wir fordern Sie niemals auf, eine Telefonnummer anzurufen, eine SMS an eine Telefonnummer zu senden oder persönliche Daten preiszugeben. Bitte melden Sie verdächtige Aktivitäten über die Funktion „Missbrauch melden“.

Weitere Informationen

Should .toLocaleDateString() use your preferred language?

  • 2 Antworten
  • 1 hat dieses Problem
  • 30 Aufrufe
  • Letzte Antwort von BytesNZ

more options

Just noticed that a web site I am working on is displaying the wrong format for the date. I am generating date string using Date.prototype.toLocaleDateString() (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString). I have changed my preferred language in the browser preferences to be [en-NZ, en-GB, en]. Checking `navigator.language` returns "en-NZ", but running

``` date = new Date(); date.toLocaleDateString() ```

returns "3/29/2020" instead of the expected "29/03/2020" as returned by `date.toLocaleDateString('en-NZ')`

Is it just me or is this a bug?

Just noticed that a web site I am working on is displaying the wrong format for the date. I am generating date string using Date.prototype.toLocaleDateString() (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString). I have changed my preferred language in the browser preferences to be [en-NZ, en-GB, en]. Checking `navigator.language` returns "en-NZ", but running ``` date = new Date(); date.toLocaleDateString() ``` returns "3/29/2020" instead of the expected "29/03/2020" as returned by `date.toLocaleDateString('en-NZ')` Is it just me or is this a bug?

Geändert am von BytesNZ

Alle Antworten (2)

more options

What is reported on the "Help -> Troubleshooting Information" (about:support) page under "Internationalization & Localization" ?

more options

Ah. Cool page (about:support). It was showing Application Settings Requested Locales ["en-US"] Available Locales ["en-US"] App Locales ["en-US"] Regional Preferences ["en-GB"] Default Locale "en-US" Operating System System Locales ["en-NZ"] Regional Preferences ["en-GB"]

I have now installed the en-GB language pack, so it is now Application Settings Requested Locales ["en-US"] Available Locales ["en-US","en-GB"] App Locales ["en-US","en-GB"] Regional Preferences ["en-GB"] Default Locale "en-US" Operating System System Locales ["en-NZ"] Regional Preferences ["en-GB"]

but still outputting en-US dates.

I have just tried installing the en-GB version of firefox dev (it is now the default download version now (I guess) that I changed my preferred language). It now displays dates as en-GB dates.

Application Settings Requested Locales ["en-GB"] Available Locales ["en-GB","en-US"] App Locales ["en-GB","en-US"] Regional Preferences ["en-GB"] Default Locale "en-GB" Operating System System Locales ["en-NZ"] Regional Preferences ["en-GB"]

I would still have thought changing the preferred language would have changed the date format though (as you have to dig to find download the browser in another locale [there is no link on the dev version download page, but I found https://www.mozilla.org/en-GB/firefox/all/#product-desktop-developer from the main firefox download page]).