0

I have the following JS code (just run it in the console)

let a = new Date();
let dateoptions = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
console.log(a.toLocaleDateString('nb-NO', dateoptions));

In firefox I get the expected format:
"mandag 16. august 2021"

But in chrome I get
"Monday, August 16, 2021" if the browser language is et to "en(USA)"
"2021 M08 16, Mon" if the browser language is set to "Norwegian bokmål"

This is version "92.0.4515.131" of chrome. Is this a new bug in Chrome, or am I doing something wrong?

Liam
  • 27,717
  • 28
  • 128
  • 190
devzero
  • 2,510
  • 4
  • 35
  • 55
  • `Is this a new bug in Chrome` try a different version of Chrome – Bravo Aug 16 '21 at 10:17
  • 2
    [Yes, it's a bug in Chromium](https://bugs.chromium.org/p/chromium/issues/detail?id=1233509&q=locale&can=2) more specifically. – VLAZ Aug 16 '21 at 10:20
  • The [specification in this area is wooly](https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.tolocaledatestring). *The contents of the String are implementation-defined, but are intended to represent the “date” portion of the Date in the current time zone in a convenient, human-readable form that corresponds to the conventions of the host environment's current locale.* so I wouldn't rely on this functionality. Better to use something like [luxon](https://moment.github.io/luxon/#/intl) – Liam Aug 16 '21 at 10:20
  • @VLAZ please respond as an answer so I can mark it – devzero Aug 16 '21 at 10:22
  • No need @devzero this question has been closed as a dupe – Liam Aug 16 '21 at 10:22
  • *Better to use something like* Firefox – Bravo Aug 16 '21 at 10:26

0 Answers0