Javascript Intl.DateTimeFormat hours12在Chrome上提供奇数输出 [英] Javascript Intl.DateTimeFormat hours12 gives odd output on Chrome

查看:33
本文介绍了Javascript Intl.DateTimeFormat hours12在Chrome上提供奇数输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了Chrome上的行为,其中将Hours12设置为true格式化的12:00 pm时间的返回值为0 pm.不应该是12点吗?如果没有,显示12小时时钟的正确方法是什么?请注意,我只能使用ES5.

I'm seeing behavior on Chrome where the return value for a 12:00 pm time formatted with hours12 set to true comes out as 0 pm. Shouldn't it be 12? If not, what's the proper way to display a 12 hour clock? Note that I'm constrained to using ES5.

Chrome浏览器中的以下内容可打印0 pm:

The following in Chrome prints 0 pm:

var foo = new Date(2020, 0, 1, 12, 0, 0)
var bar = new Intl.DateTimeFormat("en-GB", {hour12: true, hour: "numeric"}).format(foo)
console.log(bar)

请注意,bar的值为"0 pm".除了en-GB以外的其他语言也表现出这种现象.但是,在en-US上运行的相同代码给了我'12 PM'.是英国人和其他人实际上使用"0 pm"来表示中午吗?这是Chrome中的错误吗?在FF或IE中不会发生.

Note that the value of bar is '0 pm'. Other languages besides en-GB exhibit this behavior. The same code run with en-US, though, gives me '12 PM'. Is it that the British and others actually use '0 pm' to indicate noon? Is this a bug in Chrome? It does not happen in FF or IE.

感谢您的任何输入.

推荐答案

不确定您是否还在寻找解决方案...我也遇到了同样的问题,但是发现使用 hourCycle:'h12'代替了 hour12:true

Not sure if you're still looking for a solution... I had the same problem too but found that using hourCycle: 'h12' worked instead of hour12: true

这篇关于Javascript Intl.DateTimeFormat hours12在Chrome上提供奇数输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆