大网数据广告活动
Web 标准与前端开发

Intl.DateTimeFormat.prototype.resolvedOptions()

· 52CE 我爱测

The **`resolvedOptions()`** method of Intl.DateTimeFormat instances returns a new object with properties reflecting the options computed during initialization of this `DateTimeFormat` object.

The resolvedOptions() method of Intl.DateTimeFormat instances returns a new object with properties reflecting the options computed during initialization of this DateTimeFormat object.

JavaScript Demo: Intl.DateTimeFormat.prototype.resolvedOptions()

const region = new Intl.DateTimeFormat("zh-CN", { timeZone: "UTC" });
const options = region.resolvedOptions();

console.log(options.locale);
// Expected output: "zh-CN"

console.log(options.calendar);
// Expected output: "gregory"

console.log(options.numberingSystem);
// Expected output: "latn"

Syntax

resolvedOptions()

Parameters

None.

Return value

A new object with properties reflecting the options computed during the initialization of this DateTimeFormat object. The object has the following properties, in the order they are listed:

  • locale

    • : The BCP 47 language tag for the locale actually used, determined by the locale negotiation process. Only the ca, hc, and nu Unicode extension keys, if requested, may be included in the output.
  • calendar

    • : The value provided for this property in the options argument, or using the Unicode extension key "ca", with default filled in as needed. It is a supported calendar type for this locale. The default is locale dependent.
  • numberingSystem

    • : The value provided for this property in the options argument, or using the Unicode extension key "nu", with default filled in as needed. It is a supported numbering system for this locale. The default is locale dependent.
  • timeZone

    • : The value provided for this property in the options argument, with default filled in as needed. It is an IANA time zone name or an offset time zone identifier. The default is the runtime's default time zone.

      [!NOTE] The standardization of Temporal requires browsers to use the same identifier as originally specified, without canonicalization to a different alias. See time zones and offsets for more information.

  • hourCycle

    • : The value provided for this property in the options argument, or using the Unicode extension key "hc", with default filled in as needed. If hour12 was provided in the options, then that overrides other hourCycle settings. It is only present if the resolved options also include hour or timeStyle. It is either "h11", "h12", "h23", or "h24". The default is locale dependent, although "h24" is never a default.
  • hour12

    • : Calculated from hourCycle. It is only present if the resolved options also include hour or timeStyle. It is true if hourCycle is "h11" or "h12", and false if hourCycle is "h23" or "h24".
  • weekday, era, year, month, day, dayPeriod, hour, minute, second, fractionalSecondDigits, timeZoneName

    • : The values resulting from format matching between the corresponding properties in the options argument and the available combinations and representations for date-time formatting in the selected locale. Some of these properties may not be present, indicating that the corresponding components will not be represented in formatted output. weekday, era, and dayPeriod are either "narrow", "short", or "long"; year, day, hour, minute, and second are either "numeric" or "2-digit"; month is either "numeric", "2-digit", "narrow", "short", or "long"; fractionalSecondDigits is either 1, 2, or 3; timeZoneName is either "short", "long", "shortOffset", "longOffset", "shortGeneric", or "longGeneric".

      If these properties were requested in options, the constructor prevents dateStyle and timeStyle from being specified, so the below group will never be present.

  • dateStyle, timeStyle

    • : The values provided for these properties in the options argument. They are either "full", "long", "medium", or "short". Some of these properties may not be present, indicating that the corresponding components will not be represented in formatted output.

      If these properties were requested in options, the constructor prevents individual date time component options from being specified, so the above group will never be present.

      [!NOTE] Although dateStyle and timeStyle are shortcuts for individual date and time component styles, the exact (locale dependent) component styles they resolve to are not included in the resolved options. This ensures the result of resolvedOptions() can be passed directly to the Intl.DateTimeFormat() constructor (because an options object with both dateStyle or timeStyle and individual date or time component styles is not valid).

Examples

Using the resolvedOptions method

const germanFakeRegion = new Intl.DateTimeFormat("de-XX", { timeZone: "UTC" });
const usedOptions = germanFakeRegion.resolvedOptions();

usedOptions.locale; // "de" (because "de-XX" does not exist)
usedOptions.calendar; // "gregory"
usedOptions.numberingSystem; // "latn"
usedOptions.timeZone; // "UTC"
usedOptions.month; // "numeric"

Getting the user's time zone and locale preferences

The Intl.DateTimeFormat constructor without any options uses the current system settings. You can use resolvedOptions() to get the user's current time zone and locale's preferred calendar and numbering system:

const systemOptions = new Intl.DateTimeFormat().resolvedOptions();
systemOptions.timeZone; // e.g., "Europe/Brussels" or "Asia/Riyadh"
systemOptions.calendar; // e.g., "gregory" or "islamic-umalqura"
systemOptions.numberingSystem; // e.g., "latn" or "arab"
systemOptions.locale; // e.g., "nl-BE" or "ar-SA"

Specifications

Browser compatibility

See also

  • Intl.DateTimeFormat

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。