以下调用返回 24:00
在最新的 Chrome 和 Opera 中,而之前返回 00:00
,这是设计行为吗?
const [, time] = new Date(2020, 1, 1, 0, 0).toLocaleDateString("en-us",
{
hour12: false,
hour: "2-digit",
minute: "2-digit"
}).split(", ");
console.info(time); // 24:00
最佳答案
使用hourCycle
而不是 hour12
并将其设置为 h23
.
const [, time] = new Date(2020, 1, 1, 0, 0).toLocaleDateString("en-us",
{
hourCycle: "h23",
hour: "2-digit",
minute: "2-digit"
}).split(", ");
console.info(time); // 00:00
关于javascript - toLocaleDateString 返回意外的格式化时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60655166/