2

I have JavaScript code which displays the current date in en-CA format.

date = new Date();
console.log(date.toLocaleDateString('en-CA'));

Previously the en-CA locale formatted dates as yyyy-MM-dd (2023-02-24). However, as of today these dates suddenly started displaying as M/d/yyyy (2/24/2023) without me making any changes to the code. I've reproduced this issue across two different computers running Chrome, Firefox, and Edge on Windows 10 & 11.

Why did the en-CA locale start formatting dates as M/d/yyyy instead of yyyy-MM-dd?

Stevoisiak
  • 23,794
  • 27
  • 122
  • 225

3 Answers3

2

Because a mistake in unicode CLDR component version 42 was rolled out into Chrome, Edge, Firefox and Node 19 in Feb 2023. It is currently expected to be reverted in version 43. Safari seems to have avoided it.

In the case of Chrome, they expect to correct this in the next release 111 whatever the CLDR release cycle is.

Stevoisiak
  • 23,794
  • 27
  • 122
  • 225
Chris F Carroll
  • 11,146
  • 3
  • 53
  • 61
  • 1
    I can confirm the date format for `en-CA` was reverted in Chrome 111. – Stevoisiak Mar 10 '23 at 21:31
  • in Android WebView still issue remains. Can anyone also check and confirm. I tried and still returning wrong format in android webview. Device chrome browser is updated to 111. – mitsena Mar 23 '23 at 18:00
1

Apparently the en-CA format was changed in Chrome 110 and Firefox 110.

The exact format of .toLocaleDateString('en-CA') is not portable and will break in newer browsers! It recently changed from yyyy-MM-dd to M/d/yyyy in browsers with ICU 72 (Chrome 110 and Firefox 110 beta). Do not make assumptions about specific the specific formatting of locales. Use one of the answers based on .toISOString()

Anders Kaseorg

This is also noted in a GitHub Issue for Node v19.1.0.

Node >= v19.1.0 ships with a newer version of ICU (i18n library), that's why there's a difference.

There's no bug, it's working as expected.

bnoordhuis

Stevoisiak
  • 23,794
  • 27
  • 122
  • 225
0

In new 111 version of Chrome its rolled out Check it

But its more safety to use native date convert in necesary format

  • in Android WebView still issue remains. Can anyone also check and confirm. I tried and still returning wrong format in android webview. Device chrome browser is updated to 111. – mitsena Mar 23 '23 at 17:59