'DateTime Internationalization not working for Norwegian (Nynorsk) locale
When trying to display the datetime value in Norwegian (Nynorsk) locale, using the javascript internationalization api, I get unexpected results.
I'm using the ISO 639 code for Norwegian (Nynorsk) locale, which is nn, but that does not work as expected.
Sample javascript code to print datetime value in the browser console (Google Chrome, language: English)
console.log(
new Date().toLocaleDateString('nn', { dateStyle: 'full' })
)
// output: 'Monday, May 9, 2022'
// expected output: 'mandag 9. mai 2022'
Any ideas where I'm going wrong?
Am I using the correct locale code? I've tried nn-NO as well, but same results. The locale codes no and nb work, but I can't use them since I guess they map to the Norwegian (Bokmål) locale.
Solution 1:[1]
You can for now use nb - the bokmål date is understood by all Norwegian
the nn(-NO) is a valid locale - it seems to be a Chrome bug
the code below works in Edge browser but not in Chrome 100
console.log(
new Date().toLocaleDateString('nb', { dateStyle: 'full' })
)
// expected and actual output: 'mandag 9. mai 2022'
console.log(
new Date().toLocaleDateString('nn', { dateStyle: 'full' })
)
// actual output in Chrome: 'Monday 9. May 2022'
// actual output in Edge: måndag 9. mai 2022
// testing this
console.log(
Intl.NumberFormat.supportedLocalesOf(["no", "no-NO", "nb", "nb-NO", "nn", "nn-NO"])
)
// I get [ "no", "no-NO", "nb", "nb-NO" ] in Chrome 100
// and [ "no", "no-NO", "nb", "nb-NO", "nn", "nn-NO" ] in Edge
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
