Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

Hierdie gesprek is in die argief. Vra asseblief 'n nuwe vraag as jy hulp nodig het.

Should .toLocaleDateString() use your preferred language?

  • 2 antwoorde
  • 1 het hierdie probleem
  • 30 views
  • Laaste antwoord deur 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?

Gewysig op deur BytesNZ

All Replies (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]).