Pesquisar no apoio

Evite burlas no apoio. Nunca iremos solicitar que telefone ou envie uma mensagem de texto para um número de telefone ou que partilhe informações pessoais. Por favor, reporte atividades suspeitas utilizando a opção "Reportar abuso".

Learn More

Should .toLocaleDateString() use your preferred language?

  • 2 respostas
  • 1 tem este problema
  • 30 visualizações
  • Última resposta por 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?

Modificado por BytesNZ a

Todas as respostas (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]).