Intl.Locale.prototype.hourCycle
Intl.Locale
实例的 hourCycle
访问器属性返回此区域设置的小时周期类型。
¥The hourCycle
accessor property of Intl.Locale
instances returns the hour cycle type for this locale.
描述
¥Description
世界各地使用的计时约定(时钟)主要有两种类型:12 小时制和 24 小时制。hourCycle
属性的值是在构造时通过区域设置标识符的 hc
键或通过 Intl.Locale()
构造函数的 hourCycle
选项设置的。如果两者都存在,则后者优先;如果两者都不存在,则该属性的值为 undefined
。
¥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's value is set at construction time, either through the hc
key of the locale identifier or through the hourCycle
option of the Intl.Locale()
constructor. The latter takes priority if they are both present; and if neither is present, the property has value undefined
.
有关支持的小时周期类型的列表,请参阅 Intl.Locale.prototype.getHourCycles()
。
¥For a list of supported hour cycle types, see Intl.Locale.prototype.getHourCycles()
.
hourCycle
的集合访问器是 undefined
。你不能直接更改此属性。
¥The set accessor of hourCycle
is undefined
. You cannot change this property directly.
示例
¥Examples
与其他区域设置子标签一样,可以通过区域设置字符串或构造函数的配置对象参数将小时周期类型添加到 Intl.Locale
对象。
¥Like other locale subtags, the hour cycle type can be added to the Intl.Locale
object via the locale string, or a configuration object argument to the constructor.
通过区域设置字符串添加小时周期
¥Adding an hour cycle via the locale string
在 Unicode 语言环境字符串规范 中,小时周期类型是区域设置键 "扩展子标签"。这些子标签添加有关区域设置的附加数据,并使用 -u
扩展添加到区域设置标识符中。因此,可以将小时周期类型添加到传递到 Intl.Locale()
构造函数的初始区域设置标识符字符串中。要添加小时周期类型,请首先将 -u
扩展键添加到字符串中。接下来,添加 -hc
扩展名以指示你要添加小时周期。最后,将小时周期类型添加到字符串中。
¥In the Unicode locale string spec, hour cycle types are locale key "extension subtags". These subtags add additional data about the locale, and are added to locale identifiers by using the -u
extension. Thus, the hour cycle type can be added to the initial locale identifier string that is passed into the Intl.Locale()
constructor. To add the hour cycle type, first add the -u
extension key to the string. Next, add the -hc
extension to indicate that you are adding an hour cycle. Finally, add the hour cycle type to the string.
const locale = new Intl.Locale("fr-FR-u-hc-h23");
console.log(locale.hourCycle); // "h23"
通过配置对象参数添加小时周期
¥Adding an hour cycle via the configuration object argument
Intl.Locale()
构造函数有一个可选的配置对象参数,它可以包含多种扩展类型中的任何一种,包括小时周期类型。将配置对象的 hourCycle
属性设置为所需的小时周期类型,然后将其传递到构造函数中。
¥The 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.
const locale = new Intl.Locale("en-US", { hourCycle: "h12" });
console.log(locale.hourCycle); // "h12"
规范
Specification |
---|
ECMAScript Internationalization API Specification # sec-Intl.Locale.prototype.hourCycle |
浏览器兼容性
BCD tables only load in the browser
也可以看看
¥See also
Intl.Locale
Intl.Locale.prototype.getHourCycles()
- Unicode 区域设置数据标记语言规范中的 Unicode 小时周期标识符