Intl.DateTimeFormat显示时间为24:59 [英] Intl.DateTimeFormat shows time being 24:59
问题描述
大家好|只是检查我是否做错了什么。下面的代码给了我布拉格(GMT + 1)的时间= 24:59。
Hey everyone| just checking if I am doing something wrong. The code below gives me time = 24:59, in Prague (GMT+1). Using Chrome.
new Intl.DateTimeFormat(
'en',
{
weekday: 'long',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
hour12: false
}
).format(new Date('2020-03-11T23:59:00Z')
)
// "Thursday, March 12, 24:59"
使用.getHours()时,我会得到正确的值为0。
When using the .getHours() I will get a correct value of 0 though.
new Date('2020-03-11T23:59:00Z'); // Thu Mar 12 2020 00:59:00 GMT+0100 (Central European Standard Time)
new Date('2020-03-11T23:59:00Z').getHours(); // 0
感谢您的建议,我没有发现与此相关的任何问题。
Thanks for suggestions, I didn't found any related issues about this.
Tomas
推荐答案
您的代码给了我星期四,在Firefox中为3月12日,00:59
和在Chrome(80.0.3987.149)中为 3月12日,星期四,24:59
Your code gives me "Thursday, March 12, 00:59"
in Firefox and "Thursday, March 12, 24:59"
in Chrome (80.0.3987.149)
Chrome 80似乎已打开一个错误 https://support.google.com/chrome/thread/29828561?hl=zh_CN ,自2月开始开放,但是关于是否将其修复以及如何修复的说法很少。考虑对其进行投票。
There appears to be a bug open for Chrome 80 https://support.google.com/chrome/thread/29828561?hl=en, open since February, but not much is said about whether it will be fixed and how. Consider upvoting it.
根据此处发布的评论,您可以通过替换 hour12
属性来解决此问题。与 hourCycle:'h23'
。
According to a comment posted there, you could work around the issue by replacing the hour12
property with hourCycle: 'h23'
.
new Intl.DateTimeFormat(
'en',
{
weekday: 'long',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
hourCycle: 'h23'
}
).format(new Date('2020-03-11T23:59:00Z')
)
// "Thursday, March 12, 00:59"
此似乎对我来说有用
这篇关于Intl.DateTimeFormat显示时间为24:59的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!