最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why is Google Chrome showing dates in US format when both my Chrome language and OS locale are set to non-US values

programmeradmin1浏览0评论

I'm running Fedora 31 (but had the same issue on Fedora 29) and Google Chrome (78.0.3904.87 Official Build 64-bit). Sometime in the last 6 months, I noticed that dates were ing up in US format (mm/dd/yyyy) rather than the dd/mm/yyyy format that I'd expect to see.

Searching similar issues online, the answer always seemed to be to change the language within Google settings and, indeed, when I checked, the default language was English (US). However, when I selected English (UK) as the only language within Chrome, this did not fix the issue. Even selecting only German (Germany) as the language did not fix the issue.

I could see from .html that my browser language was set correctly (navigator.language: en-GB) but could also see from the same page that date.toLocaleDateString() was still returning the dates in US format.

I also checked the output of localectl in a terminal and this returned en_IE.utf-8 as expected.

So, both my OS and my browser are definitely set to non-US locales and yet I still get US date formats. I've spent an inordinately large amount of time banging my head against a wall on this, which seems like something so small. Any ideas?

I'm running Fedora 31 (but had the same issue on Fedora 29) and Google Chrome (78.0.3904.87 Official Build 64-bit). Sometime in the last 6 months, I noticed that dates were ing up in US format (mm/dd/yyyy) rather than the dd/mm/yyyy format that I'd expect to see.

Searching similar issues online, the answer always seemed to be to change the language within Google settings and, indeed, when I checked, the default language was English (US). However, when I selected English (UK) as the only language within Chrome, this did not fix the issue. Even selecting only German (Germany) as the language did not fix the issue.

I could see from http://www.localeplanet./support/browser.html that my browser language was set correctly (navigator.language: en-GB) but could also see from the same page that date.toLocaleDateString() was still returning the dates in US format.

I also checked the output of localectl in a terminal and this returned en_IE.utf-8 as expected.

So, both my OS and my browser are definitely set to non-US locales and yet I still get US date formats. I've spent an inordinately large amount of time banging my head against a wall on this, which seems like something so small. Any ideas?

Share asked Nov 5, 2019 at 12:12 PandabatPandabat 691 silver badge7 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

When looking for an answer, I noticed at least one other user here (karora in How/Where does JavaScript detect the default locale? - maybe someone with sufficient reputation might let him know of this) had the same issue that I had had and clicking on his profile revealed that he too was based in Ireland. It got me thinking about something that I'd read in one of the Chromium bug reports about Chrome's supported locales.

So, what I discovered is that when I changed my OS locale from en_IE to en_GB, my issue was fixed and Google Chrome was able to display dates in the format that I expect. What seems to occur is that if your OS is set to a locale that is not in the officially supported language list within Google Chrome then the mismatch between browser and OS language/locale either causes the browser to ignore it's own language/locale setting or causes some issue with the javascript engine therein and makes it default back to en_US formatting for dates, times, etc.

I'll raise this as a bug within the Chromium project but hopefully this post will save some time for people who find themselves in a similar situation.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论