Intl.DateTimeFormat.prototype.resolvedOptions()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2017.
The resolvedOptions()
method of Intl.DateTimeFormat
instances returns a new object with properties reflecting the locale and date and time formatting options computed during initialization of this Intl.DateTimeFormat
object.
Try it
Syntax
resolvedOptions()
Parameters
None.
Return value
A new object with properties reflecting the options computed during the initialization of the given Intl.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. Only the
ca
,hc
, andnu
Unicode extension keys may be included in the output. calendar
-
One of the supported calendar types, reflecting the value provided for this property in the
options
argument or theca
Unicode extension key. The default is locale dependent. numberingSystem
-
One of the supported numbering system types, reflecting the value provided for this property in the
options
argument or thenu
Unicode extension key. The default is locale dependent. timeZone
-
One of the IANA time zone names, reflecting the value provided for this property in the
options
argument. The default is the runtime's default time zone; should never beundefined
.Note: While the IANA database changes from time to time, the Unicode CLDR database (which browsers use) keeps old time zone names for stability purposes. All browsers canonicalize time zone names, but in different directions. For example,
new Intl.DateTimeFormat("en-US", { timeZone: "Europe/Kiev" }).resolvedOptions().timeZone
andnew Intl.DateTimeFormat("en-US", { timeZone: "Europe/Kyiv" }).resolvedOptions().timeZone
will return the same string in the same browser, but maybe different strings in different browsers. SeeIntl.Locale.prototype.getTimeZones
for more information. hourCycle
-
The value provided for this property in the
options
argument, or provided in the Unicode extension key"hc"
, with default filled in as needed. Only present if theoptions
argument includedhour
ortimeStyle
. hour12
-
The value provided for this property in the
options
argument, or computed from thehourCycle
property. Only present if theoptions
argument includedhour
ortimeStyle
. 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. If thedateStyle
ortimeStyle
shortcuts were used inoptions
, these individual component properties will never be present. dateStyle
,timeStyle
-
The values provided for these properties in the
options
argument, if any.
Description
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
Specification |
---|
ECMAScript Internationalization API Specification # sec-intl.datetimeformat.prototype.resolvedoptions |
Browser compatibility
BCD tables only load in the browser