我使用的是 Chrome 浏览器(版本 92.0.4515.131)。
我发现对 JavaScript Intl 的支持不能正常运行Chrome浏览器。
const formattedDate = new Intl.DateTimeFormat('nb-NO', {
"year": "numeric",
"month": "2-digit",
"day": "2-digit"
}).format(new Date('2021-08-02'));
console.log(formattedDate);
Chrome 给出的结果是“08/02/2021”,而不是像 Firefox 中预期的“02.08.2021”。
JavaScript 功能定义在ECMA https://tc39.es/ecma402/#datetimeformat-objects and MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat提及浏览器兼容性。
为了使其在 Chrome 中正常工作,我们需要添加任何修改吗?
See Intl.ListFormat.supportedLocalesOf() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat/supportedLocalesOf
当我跑步时Intl.ListFormat.supportedLocalesOf(['en', 'de', 'nb'])
在 Chrome 和 Firefox 中:
- Chrome 报告支持英语和德语
- Firefox 报告支持英语、德语和挪威语
问题不在于缺乏支持Intl
(如果不支持的话会抛出错误)但是nb-NO
特别是语言环境。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)