當嘗試使用 javascript 國際化 api 在挪威(尼諾斯克)語言環境中顯示日期時間值時,我得到了意想不到的結果。
我正在使用挪威(尼諾斯克)語言環境的 ISO 639 代碼,即nn,但這不能按預期作業。
在瀏覽器控制臺中列印日期時間值的示例 javascript 代碼(谷歌瀏覽器,語言:英語)
console.log(
new Date().toLocaleDateString('nn', { dateStyle: 'full' })
)
// output: 'Monday, May 9, 2022'
// expected output: 'mandag 9. mai 2022'
有什么想法我哪里出錯了嗎?
我是否使用了正確的語言環境代碼?我也試過nn-NO了,但結果一樣。語言環境代碼no和nb作業,但我不能使用它們,因為我猜它們映射到挪威(博克馬爾)語言環境。
uj5u.com熱心網友回復:
您現在可以使用nb- 所有挪威人都理解 bokm?l 日期
nn(-NO) 是一個有效的語言環境 ——它似乎是一個 Chrome 錯誤
下面的代碼適用于 Edge 瀏覽器,但不適用于 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/471370.html
標籤:javascript 国际化 日期时间格式
上一篇:如何在任何連續范圍內獲得最大值
