Intl.Locale.prototype.hourCycle property is an accessor property that returns the time keeping format convention used by the locale.

描述

There are 2 main types of time keeping conventions (clocks) used around the world: the 12 hour clock and the 24 hour clock. The hourCycle property makes it easier for JavaScript programmers to access the clock type used by a particular locale. Like other additional locale data, hour cycle type is an extension subtag , which extends the data contained in a locale string. The hour cycle type can have several different values, which are listed in the table below.

Valid hour cycle types

Hour cycle type 描述
h12 Hour system using 1–12; corresponds to 'h' in patterns. The 12 hour clock, with midnight starting at 12:00 am.
h23 Hour system using 0–23; corresponds to 'H' in patterns. The 24 hour clock, with midnight starting at 0:00.
h11 Hour system using 0–11; corresponds to 'K' in patterns. The 12 hour clock, with midnight starting at 0:00 am.
h24 Hour system using 1–24; corresponds to 'k' in pattern. The 24 hour clock, with midnight starting at 24:00.

范例

These examples will show you how to add hour cycle data to your Locale 对象。

Adding an hour cycle via the locale string

Unicode locale string spec , the hour cycle is a locale string "extension subtag". These subtags add additional data about the locale, and are added to locale identifiers by using the -u extension key. Thus, the hour cycle type can be added to the inital locale identifier string that is passed into the Locale constructor. To add the hour cycle type, first add the -u extension key to the string. Next, add the -hc extension key to indicate that you are adding an hour cycle. Finally, add the hour cycle type to the string.

let fr24hour = new Intl.Locale("fr-FR-u-hc-h23");
console.log(fr24hour.hourCycle); // Prints "h23"
					

Adding an hour cycle via the configuration object argument

Intl.Locale constructor has an optional configuration object argument, which can contain any of several extension types, including hour cycle types. Set the hourCycle property of the configuration object to your desired hour cycle type, and then pass it into the constructor.

let us12hour = new Intl.Locale("en-US", {hourCycle: "h12"});
console.log(us12hour.hourCycle); // Prints "h12"
					

规范

规范
ECMAScript 国际化 API (ECMA-402)

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
hourCycle Chrome 74 Edge 79 Firefox 75 IE No Opera 62 Safari 14 WebView Android 74 Chrome Android 74 Firefox Android No Opera Android 53 Safari iOS 14 Samsung Internet Android 11.0 nodejs 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() 构造函数 了解更多细节。

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

另请参阅

元数据

  • 最后修改: