搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

Learn More

Should .toLocaleDateString() use your preferred language?

  • 2 回覆
  • 1 有這個問題
  • 25 次檢視
  • 最近回覆由 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?

由 BytesNZ 於 修改

所有回覆 (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]).