Intl.DateTimeFormat 不关心“2 位数字”或“数字”

问题描述 投票:0回答:0

我想使用 IntlDateTimeFormat 来提供前导零。 我的代码是:

const timeFormatter = Intl.DateTimeFormat(undefined,{minute: '2-digit'});

const date = new Date();
date.setMinutes(4);

console.log(timeFormatter.format(date));  // PRINTS: 4 and not 04

但是,当我将

second: '2-digit'
添加到选项对象时。然后它工作正常,但也打印秒(是的,我可以使用替换删除它)。

“2-digit”和“numeric”有什么区别?

到目前为止,我忽略了 padStart。

我试图将配置更改回“数字”而不是“2 位数字”。好像没什么区别

javascript datetime time datetime-format intl
© www.soinside.com 2019 - 2024. All rights reserved.