对于 en-US,toLocaleDateString 正在将“00:30”转换为 24:30
For en-US, toLocaleDateString is converting “00:30” to 24:30
为什么时间 00:30 在 en-US 语言环境中被转换为 24:30
options = {
year: "numeric",
day: "numeric",
month: "numeric",
hour: '2-digit',
minute: '2-digit',
hour12: false
}
let actualDate = value;
if (typeof value == "string") { actualDate = new Date(value); }
//this also return me 24:30 for 00:30
var time = actualDate.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hour12: false});
//this also return me Date and time where 24:30 is converted in 00:30
actualDate.toLocaleDateString('en-US', options);
但是当我在上面的语言环境方法中传递 'en-GB'(英国英语)时,它 return 我 00:30 for 00:30
var time = actualDate.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hour12: false});
actualDate.toLocaleDateString('en-US', options);
现在我真的很困惑。因为据我所知,关于 24 小时格式的是没有所谓的 24:30 (00:00 - 23:59) 。但是通过更改取决于用户首选项的区域设置(可以是任何区域设置),值会发生变化。我的问题是 - ** 根据美国英语,有没有像 24:30(12:30 午夜的 24 小时制)这样的时间 **
你可以试试hourCycle.
The Intl.Locale.prototype.hourCycle property is an accessor property that returns the time keeping format convention used by the locale.
h23 Hour system using 0–23; corresponds to 'H' in patterns. The 24
hour clock, with midnight starting at 0:00.
var time = actualDate.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hourCycle: "h23"});
但是,我的总体印象是,en-US 语言环境将 AM/PM 作为默认格式(hour12 或 hourCycle: "h12"),因此您基本上会覆盖默认值。
为什么时间 00:30 在 en-US 语言环境中被转换为 24:30
options = {
year: "numeric",
day: "numeric",
month: "numeric",
hour: '2-digit',
minute: '2-digit',
hour12: false
}
let actualDate = value;
if (typeof value == "string") { actualDate = new Date(value); }
//this also return me 24:30 for 00:30
var time = actualDate.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hour12: false});
//this also return me Date and time where 24:30 is converted in 00:30
actualDate.toLocaleDateString('en-US', options);
但是当我在上面的语言环境方法中传递 'en-GB'(英国英语)时,它 return 我 00:30 for 00:30
var time = actualDate.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hour12: false});
actualDate.toLocaleDateString('en-US', options);
现在我真的很困惑。因为据我所知,关于 24 小时格式的是没有所谓的 24:30 (00:00 - 23:59) 。但是通过更改取决于用户首选项的区域设置(可以是任何区域设置),值会发生变化。我的问题是 - ** 根据美国英语,有没有像 24:30(12:30 午夜的 24 小时制)这样的时间 **
你可以试试hourCycle.
The Intl.Locale.prototype.hourCycle property is an accessor property that returns the time keeping format convention used by the locale.
h23 Hour system using 0–23; corresponds to 'H' in patterns. The 24 hour clock, with midnight starting at 0:00.
var time = actualDate.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hourCycle: "h23"});
但是,我的总体印象是,en-US 语言环境将 AM/PM 作为默认格式(hour12 或 hourCycle: "h12"),因此您基本上会覆盖默认值。