大家好| 只是检查我是否做错了什么。下面的代码给了我时间 = 24:59,在布拉格 (GMT+1)。使用 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"
Run Code Online (Sandbox Code Playgroud)
使用 .getHours() 时,我会得到正确的 0 值。
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
Run Code Online (Sandbox Code Playgroud)
感谢您的建议,我没有发现任何与此相关的问题。
托马斯
您的代码"Thursday, March 12, 00:59"在 Firefox 和"Thursday, March 12, 24:59"Chrome (80.0.3987.149) 中为我提供
Chrome 80 https://support.google.com/chrome/thread/29828561?hl=en似乎有一个 bug ,自 2 月以来开放,但关于是否会修复以及如何修复的说法不多。考虑给它点赞。
根据那里发布的评论,您可以通过将hour12属性替换为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"
Run Code Online (Sandbox Code Playgroud)
这似乎对我有用