Intl.PluralRules.prototype.resolvedOptions() - JavaScript

Intl.PluralRules.prototype.resolvedOptions()
============================================

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

Try it
------

Syntax
------

```js
resolvedOptions()
```

### Parameters

None.

### Return value

A new object with properties reflecting the locale and plural formatting options computed during the initialization of the given `Intl.PluralRules` object.

The object has the following properties:

`locale`

The BCP 47 language tag for the locale actually used. If any Unicode extension values were requested in the input BCP 47 language tag that led to this locale, the key-value pairs that were requested and are supported for this locale are included in `locale`.

`pluralCategories`

An `Array` of plural categories used by the given locale, selected from the list `"zero"`, `"one"`, `"two"`, `"few"`, `"many"` and `"other"`.

`type`

The type used (`cardinal` or `ordinal`).

`roundingMode`
Experimental

 The rounding mode.
 This is the value provided for the `options.roundingMode` argument in the constructor, or the default value: `halfExpand`.

`roundingPriority`
Experimental

 The priority for resolving rounding conflicts if both "FractionDigits" and "SignificantDigits" are specified.
 This is the value provided for the `options.roundingPriority` argument in the constructor, or the default value: `auto`.

`roundingIncrement`
Experimental

 The rounding-increment precision (the increment used when rounding numbers).
 This is the value specified in the `options.roundingIncrement` argument in the constructor.

`trailingZeroDisplay`
Experimental

 The strategy for displaying trailing zeros on whole numbers.
 This is the value specified in the `options.trailingZeroDisplay` argument in the constructor, or the default value: `"auto"`.

Only one of the following two groups of properties is included:

`minimumIntegerDigits`, `minimumFractionDigits`, `maximumFractionDigits`

 The values provided for these properties in the `options` argument or filled in as defaults.
 These properties are present only if neither `minimumSignificantDigits` nor `maximumSignificantDigits` was provided in the `options` argument.

`minimumSignificantDigits`, `maximumSignificantDigits`

 The values provided for these properties in the `options` argument or filled in as defaults.
 These properties are present only if at least one of them was provided in the `options` argument.

Examples
--------

### Using the resolvedOptions() method

The code below shows the construction of a `PluralRules` object, followed by logging of each of the resolved options.

```js
// Create a PluralRules instance
const de = new Intl.PluralRules("de-DE", {
  maximumSignificantDigits: 2,
  trailingZeroDisplay: "auto",
});

// Resolve the options
const usedOptions = de.resolvedOptions();
console.log(usedOptions.locale); // "de-DE"
console.log(usedOptions.pluralCategories); // Array ["one", "other"]
console.log(usedOptions.type); // "cardinal"
console.log(usedOptions.minimumIntegerDigits); // 1
console.log(usedOptions.minimumFractionDigits); // undefined (maximumSignificantDigits is set)
console.log(usedOptions.maximumFractionDigits); //undefined (maximumSignificantDigits is set)
console.log(usedOptions.minimumSignificantDigits); // 1
console.log(usedOptions.maximumSignificantDigits); //2
console.log(usedOptions.roundingIncrement); // 1
console.log(usedOptions.roundingMode); // "halfExpand"
console.log(usedOptions.roundingPriority); // "auto"
console.log(usedOptions.trailingZeroDisplay); // "auto"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-intl.pluralrules.prototype.resolvedoptions |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.PluralRules`


Intl.PluralRules() constructor - JavaScript

Intl.PluralRules() constructor
==============================

The **`Intl.PluralRules()`** constructor creates `Intl.PluralRules` objects.

Syntax
------

```js
new Intl.PluralRules()
new Intl.PluralRules(locales)
new Intl.PluralRules(locales, options)
```

**Note:** `Intl.PluralRules()` can only be constructed with `new`. Attempting to call it without `new` throws a `TypeError`.

### Parameters

`locales` Optional

A string with a BCP 47 language tag or an `Intl.Locale` instance, or an array of such locale identifiers. For the general form and interpretation of the `locales` argument, see the parameter description on the `Intl` main page.

`options` Optional

An object containing the following properties, in the order they are retrieved (all of them are optional):

`localeMatcher`

The locale matching algorithm to use. Possible values are `"lookup"` and `"best fit"`; the default is `"best fit"`. For information about this option, see Locale identification and negotiation.

`type`

The type to use. Possible values are:

`"cardinal"` (default)

For cardinal numbers (referring to the quantity of things).

`"ordinal"`

For ordinal number (referring to the ordering or ranking of things, e.g. "1st", "2nd", "3rd" in English).

`Intl.PluralRules` also supports the `Intl.NumberFormat()` digit options (see `Intl.NumberFormat()` for details):

* `minimumIntegerDigits`
* `minimumFractionDigits`
* `maximumFractionDigits`
* `minimumSignificantDigits`
* `maximumSignificantDigits`
* `roundingPriority`
* `roundingIncrement`
* `roundingMode`

These options are interpreted as if the `notation` option from `Intl.NumberFormat` is `"standard"` and `style` is `"decimal"`.

### Exceptions

`RangeError`

Thrown if `locales` or `options` contain invalid values.

Examples
--------

### Basic usage

 In basic use without specifying a locale, a formatted string in the default locale and with default options is returned.
 This is useful to distinguish between singular and plural forms, e.g. "dog" and "dogs".

```js
const pr = new Intl.PluralRules();

pr.select(0); // 'other' if in US English locale

pr.select(1); // 'one' if in US English locale

pr.select(2); // 'other' if in US English locale
```

### Using options

 The results can be customized using the `options` argument, which has one property called `type` which you can set to `ordinal`. This is useful to figure out the ordinal indicator, e.g. "1st", "2nd", "3rd", "4th", "42nd",
 and so forth.

```js
const pr = new Intl.PluralRules("en-US", { type: "ordinal" });

const suffixes = new Map([
  ["one", "st"],
  ["two", "nd"],
  ["few", "rd"],
  ["other", "th"],
]);
const formatOrdinals = (n) => {
  const rule = pr.select(n);
  const suffix = suffixes.get(rule);
  return `${n}${suffix}`;
};

formatOrdinals(0); // '0th'
formatOrdinals(1); // '1st'
formatOrdinals(2); // '2nd'
formatOrdinals(3); // '3rd'
formatOrdinals(4); // '4th'
formatOrdinals(11); // '11th'
formatOrdinals(21); // '21st'
formatOrdinals(42); // '42nd'
formatOrdinals(103); // '103rd'
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-intl-pluralrules-constructor |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.PluralRules`
* `Intl`


Intl.Locale.prototype.getCalendars() - JavaScript

Intl.Locale.prototype.getCalendars()
====================================

The **`getCalendars()`** method of `Intl.Locale` instances returns a list of one or more unique calendar identifiers for this locale.

**Note:** In some versions of some browsers, this method was implemented as an accessor property called `calendars`. However, because it returns a new array on each access, it is now implemented as a method to prevent the situation of `locale.calendars === locale.calendars` returning `false`. Check the browser compatibility table for details.

Syntax
------

```js
getCalendars()
```

### Parameters

None.

### Return value

An array of strings representing all calendars commonly used for the `Locale`, sorted in descending preference. If the `Locale` already has a `calendar`, then the returned array contains that single value.

Below is a list of the supported calendar era types.

### Supported calendar types

`buddhist`

Thai Buddhist calendar

`chinese`

Traditional Chinese calendar

`coptic`

Coptic calendar

`dangi`

Traditional Korean calendar

`ethioaa`

Ethiopic calendar, Amete Alem (epoch approx. 5493 B.C.E)

`ethiopic`

Ethiopic calendar, Amete Mihret (epoch approx, 8 C.E.)

`gregory`

Gregorian calendar

`hebrew`

Traditional Hebrew calendar

`indian`

Indian calendar

`islamic`

Islamic calendar

`islamic-umalqura`

Islamic calendar, Umm al-Qura

`islamic-tbla`

Islamic calendar, tabular (intercalary years [2,5,7,10,13,16,18,21,24,26,29] - astronomical epoch)

`islamic-civil`

Islamic calendar, tabular (intercalary years [2,5,7,10,13,16,18,21,24,26,29] - civil epoch)

`islamic-rgsa`

Islamic calendar, Saudi Arabia sighting

`iso8601`

ISO calendar (Gregorian calendar using the ISO 8601 calendar week rules)

`japanese`

Japanese Imperial calendar

`persian`

Persian calendar

`roc`

Civil (algorithmic) Arabic calendar

`islamicc`

Civil (algorithmic) Arabic calendar

**Warning:** The `islamicc` calendar key has been deprecated. Please use `islamic-civil`.

Examples
--------

### Obtaining supported calendars

If the `Locale` object doesn't have a `calendar` already, `getCalendars()` lists all commonly-used calendars for the given `Locale`. For examples of explicitly setting a `calendar`, see `calendar` examples.

```js
const arEG = new Intl.Locale("ar-EG");
console.log(arEG.getCalendars()); // ["gregory", "coptic", "islamic", "islamic-civil", "islamic-tbla"]
```

```js
const jaJP = new Intl.Locale("ja-JP");
console.log(jaJP.getCalendars()); // ["gregory", "japanese"]
```

Specifications
--------------

| Specification |
| --- |
| Intl Locale Info Proposal # sec-Intl.Locale.prototype.getCalendars |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Locale`
* `Intl.Locale.prototype.calendar`
* Unicode Calendar Identifier in the Unicode locale data markup language spec


Intl.Locale.prototype.toString() - JavaScript

Intl.Locale.prototype.toString()
================================

The **`toString()`** method of `Intl.Locale` instances returns this Locale's full locale identifier string.

Try it
------

Syntax
------

```js
toString()
```

### Parameters

None.

### Return value

The *locale*'s Unicode locale identifier string.

Description
-----------

 The `Locale` object is a JavaScript representation of a concept
 Unicode locale identifier. Information about a particular locale (language, script,
 calendar type, etc.) can be encoded in a locale identifier string. To make it easier
 to work with these locale identifiers, the `Locale` object was
 introduced to JavaScript. Calling the `toString` method on a Locale object
 will return the identifier string for that particular Locale. The
 `toString` method allows `Locale` instances to be
 provided as an argument to existing `Intl` constructors, serialized in
 JSON, or any other context where an exact string representation is useful.

Examples
--------

### Using toString

```js
const myLocale = new Intl.Locale("fr-Latn-FR", {
  hourCycle: "h12",
  calendar: "gregory",
});
console.log(myLocale.baseName); // Prints "fr-Latn-FR"
console.log(myLocale.toString()); // Prints "fr-Latn-FR-u-ca-gregory-hc-h12"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-Intl.Locale.prototype.toString |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Locale`
* `baseName`


Intl.Locale.prototype.calendar - JavaScript

Intl.Locale.prototype.calendar
==============================

The **`calendar`** accessor property of `Intl.Locale` instances returns the calendar type for this locale.

Description
-----------

While most of the world uses the Gregorian calendar, there are several regional calendar eras used around the world. The `calendar` property's value is set at construction time, either through the `ca` key of the locale identifier or through the `calendar` 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`.

For a list of supported calendar types, see `Intl.Locale.prototype.getCalendars()`.

The set accessor of `calendar` is `undefined`. You cannot change this property directly.

Examples
--------

Like other locale subtags, the calendar type can be added to the `Intl.Locale` object via the locale string, or a configuration object argument to the constructor.

### Adding a calendar type via the locale string

In the Unicode locale string spec, calendar era 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 calendar era type can be added to the initial locale identifier string that is passed into the `Intl.Locale()` constructor. To add the calendar type, first add the `-u` extension to the string. Next, add the `-ca` extension to indicate that you are adding a calendar type. Finally, add the calendar era type to the string.

```js
const locale = new Intl.Locale("fr-FR-u-ca-buddhist");
console.log(locale.calendar); // Prints "buddhist"
```

### Adding a calendar type via the configuration object argument

The `Intl.Locale()` constructor has an optional configuration object argument, which can contain any of several extension types, including calendars. Set the `calendar` property of the configuration object to your desired calendar era, and then pass it into the constructor.

```js
const locale = new Intl.Locale("fr-FR", { calendar: "buddhist" });
console.log(locale.calendar); // "buddhist"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-Intl.Locale.prototype.calendar |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Locale`
* `Intl.Locale.prototype.getCalendars()`
* Unicode Calendar Identifier in the Unicode locale data markup language spec


Intl.Locale.prototype.caseFirst - JavaScript

Intl.Locale.prototype.caseFirst
===============================

The **`caseFirst`** accessor property of `Intl.Locale` instances returns whether case is taken into account for this locale's collation rules.

Description
-----------

A locale's collation rules are used to determine how strings are ordered in that locale. Certain locales use a character's case (UPPERCASE or lowercase) in the collation process. This additional rule can be expressed in a `Intl.Locale` object's `caseFirst` property.

There are 3 values that the `caseFirst` property can have, outlined in the table below.

### `caseFirst` values

| Value | Description |
| --- | --- |
| `upper` | Upper case to be sorted before lower case. |
| `lower` | Lower case to be sorted before upper case. |
| `false` | No special case ordering. |

Examples
--------

### Setting the caseFirst value via the locale string

In the Unicode locale string spec, the values that `caseFirst` represents correspond to the key `kf`. `kf` is treated as 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 `caseFirst` value can be added to the initial locale identifier string that is passed into the `Locale` constructor. To add the `caseFirst` value, first add the `-u` extension key to the string. Next, add the `-kf` extension key to indicate that you are adding a value for `caseFirst`. Finally, add the `caseFirst` value to the string.

```js
const locale = new Intl.Locale("fr-Latn-FR-u-kf-upper");
console.log(locale.caseFirst); // Prints "upper"
```

### Setting the caseFirst value via the configuration object argument

The `Intl.Locale()` constructor has an optional configuration object argument, which can be used to pass extension types. Set the `caseFirst` property of the configuration object to your desired `caseFirst` value, and then pass it into the constructor.

```js
const locale = new Intl.Locale("en-Latn-US", { caseFirst: "lower" });
console.log(locale.caseFirst); // Prints "lower"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-Intl.Locale.prototype.caseFirst |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Locale`
* Unicode case first collation spec


Intl.Locale.prototype.getWeekInfo() - JavaScript

Intl.Locale.prototype.getWeekInfo()
===================================

The **`getWeekInfo()`** method of `Intl.Locale` instances returns a `weekInfo` object with the properties `firstDay`, `weekend` and `minimalDays` for this locale.

**Note:** In some versions of some browsers, this method was implemented as an accessor property called `weekInfo`. However, because it returns a new object on each access, it is now implemented as a method to prevent the situation of `locale.weekInfo === locale.weekInfo` returning `false`. Check the browser compatibility table for details.

Syntax
------

```js
getWeekInfo()
```

### Parameters

None.

### Return value

An object representing week information associated with the Locale data specified in UTS 35's Week Elements. It has the following properties:

`firstDay`

An integer indicating the first day of the week for the locale. Can be either `1` (Monday) or `7` (Sunday).

`weekend`

An array of integers indicating the weekend days for the locale, where `1` is Monday and `7` is Sunday.

`minimalDays`

An integer between 1 and 7 indicating the minimal days required in the first week of a month or year, for calendar purposes.

Examples
--------

### Obtaining the Week Information

Return the week information for a given `Locale`.

```js
const he = new Intl.Locale("he");
console.log(he.getWeekInfo()); // { firstDay: 7, weekend: [5, 6], minimalDays: 1 }

const af = new Intl.Locale("af");
console.log(af.getWeekInfo()); // { firstDay: 7, weekend: [6, 7], minimalDays: 1 }

const enGB = new Intl.Locale("en-GB");
console.log(enGB.getWeekInfo()); // { firstDay: 1, weekend: [6, 7], minimalDays: 4 }

const msBN = new Intl.Locale("ms-BN");
console.log(msBN.getWeekInfo()); // { firstDay: 7, weekend: [5, 7], minimalDays: 1 }
// Brunei weekend is Friday and Sunday but not Saturday
```

Specifications
--------------

| Specification |
| --- |
| Intl Locale Info Proposal # sec-Intl.Locale.prototype.getWeekInfo |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Locale`


Intl.Locale.prototype.region - JavaScript

Intl.Locale.prototype.region
============================

The **`region`** accessor property of `Intl.Locale` instances returns the region of the world (usually a country) associated with this locale.

Description
-----------

The region is an essential part of the locale identifier, as it places the locale in a specific area of the world. Knowing the locale's region is vital to identifying differences between locales. For example, English is spoken in the United Kingdom and the United States of America, but there are differences in spelling and other language conventions between those two countries. Knowing the locale's region helps JavaScript programmers make sure that the content from their sites and applications is correctly displayed when viewed from different areas of the world.

Examples
--------

### Setting the region in the locale identifier string argument

The region is the third part of a valid Unicode language identifier string, and can be set by adding it to the locale identifier string that is passed into the `Intl.Locale()` constructor. The region is a mandatory part of a

```js
const locale = new Intl.Locale("en-Latn-US");
console.log(locale.region); // Prints "US"
```

### Setting the region via the configuration object

The `Intl.Locale()` constructor takes a configuration object, which can be used to set the region subtag and property.

```js
const locale = new Intl.Locale("fr-Latn", { region: "FR" });
console.log(locale.region); // Prints "FR"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-Intl.Locale.prototype.region |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Locale`
* Unicode region chart


Intl.Locale.prototype.numberingSystem - JavaScript

Intl.Locale.prototype.numberingSystem
=====================================

The **`numberingSystem`** accessor property of `Intl.Locale` instances returns the numeral system for this locale.

Description
-----------

A numeral system is a system for expressing numbers. The `numberingSystem` property's value is set at construction time, either through the `nu` key of the locale identifier or through the `numberingSystem` 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`.

For a list of supported numbering system types, see `Intl.Locale.prototype.getNumberingSystems()`.

Examples
--------

Like other locale subtags, the numbering system type can be added to the `Intl.Locale` object via the locale string, or a configuration object argument to the constructor.

### Adding a numbering system via the locale string

In the Unicode locale string spec, numbering system 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 numbering system type can be added to the initial locale identifier string that is passed into the `Intl.Locale()` constructor. To add the numbering system type, first add the `-u` extension key to the string. Next, add the `-nu` extension to indicate that you are adding a numbering system. Finally, add the numbering system type to the string.

```js
const locale = new Intl.Locale("fr-Latn-FR-u-nu-mong");
console.log(locale.numberingSystem); // "mong"
```

### Adding a numbering system via the configuration object argument

The `Intl.Locale()` constructor has an optional configuration object argument, which can contain any of several extension types, including numbering system types. Set the `numberingSystem` property of the configuration object to your desired numbering system type, and then pass it into the constructor.

```js
const locale = new Intl.Locale("en-Latn-US", { numberingSystem: "latn" });
console.log(locale.numberingSystem); // "latn"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-Intl.Locale.prototype.numberingSystem |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Locale`
* `Intl.Locale.prototype.getNumberingSystems()`
* Details on the standard Unicode numeral systems


Intl.Locale.prototype.baseName - JavaScript

Intl.Locale.prototype.baseName
==============================

The **`baseName`** accessor property of `Intl.Locale` instances returns a substring of this locale's string representation, containing core information about this locale.

Description
-----------

An `Intl.Locale` object represents a parsed local and options for that locale. The `baseName` property returns basic, core information about the Locale in the form of a substring of the complete data string. Specifically, the property returns the substring containing the language, and the script and region if available.

`baseName` returns the `language ["-" script] ["-" region] *("-" variant)` subsequence of the unicode\_language\_id grammar.

Examples
--------

### Basic Example

```js
const myLoc = new Intl.Locale("fr-Latn-CA"); // Sets locale to Canadian French
console.log(myLoc.toString()); // Prints out "fr-Latn-CA-u-ca-gregory"
console.log(myLoc.baseName); // Prints out "fr-Latn-CA"
```

### Example with options in the input string

```js
// Sets language to Japanese, region to Japan,

// calendar to Gregorian, hour cycle to 24 hours
const japan = new Intl.Locale("ja-JP-u-ca-gregory-hc-24");
console.log(japan.toString()); // Prints out "ja-JP-u-ca-gregory-hc-h24"
console.log(japan.baseName); // Prints out "ja-JP"
```

### Example with options that override input string

```js
// Input string indicates language as Dutch and region as Belgium,

// but options object overrides the region and sets it to the Netherlands
const dutch = new Intl.Locale("nl-Latn-BE", { region: "NL" });

console.log(dutch.baseName); // Prints out "nl-Latn-NL"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-Intl.Locale.prototype.baseName |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Locale`


Intl.Locale.prototype.script - JavaScript

Intl.Locale.prototype.script
============================

The **`script`** accessor property of `Intl.Locale` instances returns the script used for writing the particular language used in this locale.

Description
-----------

A script, sometimes called writing system, is one of the core attributes of a locale. It indicates the set of symbols, or glyphs, that are used to write a particular language. For instance, the script associated with English is Latin, whereas the script typically associated with Korean is Hangul. In many cases, denoting a script is not strictly necessary, since the language (which is necessary) is only written in a single script. There are exceptions to this rule, however, and it is important to indicate the script whenever possible, in order to have a complete Unicode language identifier.

Examples
--------

### Setting the script in the locale identifier string argument

The script is the second part of a valid Unicode language identifier string, and can be set by adding it to the locale identifier string that is passed into the `Intl.Locale()` constructor. Note that the script is not a required part of a locale identifier.

```js
const locale = new Intl.Locale("en-Latn-US");
console.log(locale.script); // Prints "Latn"
```

### Setting the script via the configuration object

The `Intl.Locale()` constructor takes a configuration object, which can be used to set the script subtag and property.

```js
const locale = new Intl.Locale("fr-FR", { script: "Latn" });
console.log(locale.script); // Prints "Latn"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-Intl.Locale.prototype.script |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Locale`
* Unicode script subtag in the Unicode locale data markup language spec


Intl.Locale.prototype.getTimeZones() - JavaScript

Intl.Locale.prototype.getTimeZones()
====================================

The **`getTimeZones()`** method of `Intl.Locale` instances returns a list of supported time zones for this locale.

**Note:** In some versions of some browsers, this method was implemented as an accessor property called `timeZones`. However, because it returns a new array on each access, it is now implemented as a method to prevent the situation of `locale.timeZones === locale.timeZones` returning `false`. Check the browser compatibility table for details.

Syntax
------

```js
getTimeZones()
```

### Parameters

None.

### Return value

An array of strings representing supported time zones for the associated `Locale`, where each value is an IANA time zone canonical name, sorted in alphabetical order. If the locale identifier does not contain a region subtag, the returned value is `undefined`.

Examples
--------

### Obtaining supported time zones

List supported time zones for a given `Locale`.

```js
const arEG = new Intl.Locale("ar-EG");
console.log(arEG.getTimeZones()); // ["Africa/Cairo"]
```

```js
const jaJP = new Intl.Locale("ja-JP");
console.log(jaJP.getTimeZones()); // ["Asia/Tokyo"]
```

```js
const ar = new Intl.Locale("ar");
console.log(ar.getTimeZones()); // undefined
```

Specifications
--------------

| Specification |
| --- |
| Intl Locale Info Proposal # sec-Intl.Locale.prototype.getTimeZones |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Locale`
* IANA time zone database on Wikipedia


Intl.Locale.prototype.getTextInfo() - JavaScript

Intl.Locale.prototype.getTextInfo()
===================================

The **`getTextInfo()`** method of `Intl.Locale` instances returns the ordering of characters indicated by either `ltr` (left-to-right) or by `rtl` (right-to-left) for this locale.

**Note:** In some versions of some browsers, this method was implemented as an accessor property called `textInfo`. However, because it returns a new object on each access, it is now implemented as a method to prevent the situation of `locale.textInfo === locale.textInfo` returning `false`. Check the browser compatibility table for details.

Syntax
------

```js
getTextInfo()
```

### Parameters

None.

### Return value

An object representing text typesetting information associated with the Locale data specified in UTS 35's Layouts Elements. It has the following properties:

`direction`

A string indicating the direction of text for the locale. Can be either `"ltr"` (left-to-right) or `"rtl"` (right-to-left).

Examples
--------

### Obtaining text info

Return the supported text directions for a given `Locale`.

```js
const ar = new Intl.Locale("ar");
console.log(ar.getTextInfo()); // { direction: "rtl" }
console.log(ar.getTextInfo().direction); // "rtl"
```

```js
const es = new Intl.Locale("es");
console.log(es.getTextInfo()); // { direction: "ltr" }
console.log(es.getTextInfo().direction); // "ltr"
```

Specifications
--------------

| Specification |
| --- |
| Intl Locale Info Proposal # sec-Intl.Locale.prototype.getTextInfo |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Locale`


Intl.Locale() constructor - JavaScript

Intl.Locale() constructor
=========================

The **`Intl.Locale()`** constructor creates `Intl.Locale` objects.

Try it
------

Syntax
------

```js
new Intl.Locale(tag)
new Intl.Locale(tag, options)
```

**Note:** `Intl.Locale()` can only be constructed with `new`. Attempting to call it without `new` throws a `TypeError`.

### Parameters

`tag`

The Unicode locale identifier string. For the syntax of locale identifier strings, see the Intl main page. Note that the `Intl.Locale` constructor, unlike most other `Intl` constructors, does not accept an array of locales or `undefined`.

`options`

An object that contains configuration for the Locale. Option values here take priority over extension keys in the locale identifier. Possible properties are:

`language`

The language. Any syntactically valid string following the `unicode_language_subtag` grammar (2–3 or 5–8 letters) is accepted, but the implementation only recognizes certain kinds.

`script`

The script. Any syntactically valid string following the `unicode_script_subtag` grammar (4 letters) is accepted, but the implementation only recognizes certain kinds.

`region`

The region. Any syntactically valid string following the `unicode_region_subtag` grammar (either 2 letters or 3 digits) is accepted, but the implementation only recognizes certain kinds.

`calendar`

The calendar. Any syntactically valid string following the `type` grammar (one or more segments of 3–8 alphanumerals, joined by hyphens) is accepted, but the implementation only recognizes certain kinds, which are listed in `Intl.Locale.prototype.getCalendars`.

`collation`

The collation. Any syntactically valid string following the `type` grammar is accepted, but the implementation only recognizes certain kinds, which are listed in `Intl.Locale.prototype.getCollations`.

`numberingSystem`

The numbering system. Any syntactically valid string following the `type` grammar is accepted, but the implementation only recognizes certain kinds, which are listed in `Intl.Locale.prototype.getNumberingSystems`.

`caseFirst`

The case-first sort option. Possible values are `"upper"`, `"lower"`, or `"false"`.

`hourCycle`

The hour cycle. Possible values are `"h23"`, `"h12"`, `"h11"`, or the practically unused `"h24"`, which are explained in `Intl.Locale.prototype.getHourCycles`

`numeric`

The numeric sort option. A boolean.

Examples
--------

### Basic usage

 At its very simplest, the `Intl.Locale()` constructor takes
 a locale identifier string as its argument:

```js
const us = new Intl.Locale("en-US");
```

### Using the Locale constructor with an options object

 The constructor also takes an optional configuration object argument, which can contain
 any of several extension types. For example, set the
 `hourCycle`
 property of the configuration object to your desired hour cycle type, and then pass it
 into the constructor:

```js
const locale = new Intl.Locale("en-US", { hourCycle: "h12" });
console.log(locale.hourCycle); // "h12"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-intl-locale-constructor |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `Intl.Locale` in FormatJS
* `Intl.Collator`
* Canonical Unicode Locale Identifiers in the Unicode locale data markup language spec


Intl.Locale.prototype.numeric - JavaScript

Intl.Locale.prototype.numeric
=============================

The **`numeric`** accessor property of `Intl.Locale` instances returns whether this locale has special collation handling for numeric characters.

Description
-----------

Like `caseFirst`, `numeric` represents a modification to the collation rules utilized by the locale. `numeric` is a boolean value, which means that it can be either `true` or `false`. If `numeric` is set to `false`, there will be no special handling of numeric values in strings. If `numeric` is set to `true`, then the locale will take numeric characters into account when collating strings. This special numeric handling means that sequences of decimal digits will be compared as numbers. For example, the string "A-21" will be considered less than "A-123".

Examples
--------

### Setting the numeric value via the locale string

In the Unicode locale string spec, the values that `numeric` represents correspond to the key `kn`. `kn` is considered 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 `numeric` value can be added to the initial locale identifier string that is passed into the `Intl.Locale()` constructor. To set the `numeric` value, first add the `-u` extension key to the string. Next, add the `-kn` extension key to indicate that you are adding a value for `numeric`. Finally, add the `numeric` value to the string. If you want to set `numeric` to `true`, adding the `kn` key will suffice. To set the value to `false`, you must specify in by adding `"false"` after the `kn` key.

```js
const locale = new Intl.Locale("fr-Latn-FR-u-kn-false");
console.log(locale.numeric); // Prints "false"
```

### Setting the numeric value via the configuration object argument

The `Intl.Locale()` constructor has an optional configuration object argument, which can be used to pass extension types. Set the `numeric` property of the configuration object to your desired `numeric` value and pass it into the constructor.

```js
const locale = new Intl.Locale("en-Latn-US", { numeric: true });
console.log(locale.numeric); // Prints "true"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-Intl.Locale.prototype.numeric |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Locale`


Intl.Locale.prototype.minimize() - JavaScript

Intl.Locale.prototype.minimize()
================================

 The **`minimize()`** method of `Intl.Locale` instances attempts to
 remove information about this locale that would be added by calling
 `maximize()`.

Try it
------

Syntax
------

```js
minimize()
```

### Parameters

None.

### Return value

 A `Intl.Locale` instance whose `baseName` property returns
 the result of the Remove Likely Subtags algorithm
 executed against *`locale.baseName`*.

Description
-----------

 This method carries out the reverse of `maximize()`,
 removing any language, script, or region subtags from the locale language identifier
 (essentially the contents of `baseName`). This is useful when there are
 superfluous subtags in the language identifier; for instance, "en-Latn" can be
 simplified to "en", since "Latn" is the only script used to write English.
 `minimize()` only affects the main subtags that comprise
 the language identifier:
 language, script, and region subtags. Other subtags after the "-u"
 in the locale identifier are called extension subtags and are not affected by the
 `minimize()` method. Examples of these subtags include
 `hourCycle`, `calendar`, and `numeric`.

Examples
--------

### Using minimize

```js
const myLocale = new Intl.Locale("fr-Latn-FR", {
  hourCycle: "h12",
  calendar: "gregory",
});
console.log(myLocale.baseName); // Prints "fr-Latn-FR"
console.log(myLocale.toString()); // Prints "fr-Latn-FR-u-ca-gregory-hc-h12"

const myLocMinimized = myLocale.minimize();

// Prints "fr", since French is only written in the Latin script
// and is most likely to be spoken in France.
console.log(myLocMinimized.baseName);

// Prints "fr-u-ca-gregory-hc-h12".
// Note that the extension tags (after "-u") remain unchanged.
console.log(myLocMinimized.toString());
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-Intl.Locale.prototype.minimize |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Locale`
* `baseName`


Intl.Locale.prototype.getNumberingSystems() - JavaScript

Intl.Locale.prototype.getNumberingSystems()
===========================================

The **`getNumberingSystems()`** method of `Intl.Locale` instances returns a list of one or more unique numbering system identifiers for this locale.

**Note:** In some versions of some browsers, this method was implemented as an accessor property called `numberingSystems`. However, because it returns a new array on each access, it is now implemented as a method to prevent the situation of `locale.numberingSystems === locale.numberingSystems` returning `false`. Check the browser compatibility table for details.

Syntax
------

```js
getNumberingSystems()
```

### Parameters

None.

### Return value

An array of strings representing all numbering systems commonly used for the `Locale`, sorted in descending preference. If the `Locale` already has a `numberingSystem`, then the returned array contains that single value.

A table of the standard Unicode numeral systems can be seen below.

### Supported numbering system types

| Value | Description |
| --- | --- |
| adlm | Adlam digits |
| ahom | Ahom digits |
| arab | Arabic-Indic digits |
| arabext | Extended Arabic-Indic digits |
| armn | Armenian upper case numerals — algorithmic |
| armnlow | Armenian lower case numerals — algorithmic |
| bali | Balinese digits |
| beng | Bengali digits |
| bhks | Bhaiksuki digits |
| brah | Brahmi digits |
| cakm | Chakma digits |
| cham | Cham digits |
| cyrl | Cyrillic numerals — algorithmic |
| deva | Devanagari digits |
| ethi | Ethiopic numerals — algorithmic |
| finance | Financial numerals — may be algorithmic |
| fullwide | Full width digits |
| geor | Georgian numerals — algorithmic |
| gong | Gunjala Gondi digits |
| gonm | Masaram Gondi digits |
| grek | Greek upper case numerals — algorithmic |
| greklow | Greek lower case numerals — algorithmic |
| gujr | Gujarati digits |
| guru | Gurmukhi digits |
| hanidays | Han-character day-of-month numbering for lunar/other traditional calendars |
| hanidec | Positional decimal system using Chinese number ideographs as digits |
| hans | Simplified Chinese numerals — algorithmic |
| hansfin | Simplified Chinese financial numerals — algorithmic |
| hant | Traditional Chinese numerals — algorithmic |
| hantfin | Traditional Chinese financial numerals — algorithmic |
| hebr | Hebrew numerals — algorithmic |
| hmng | Pahawh Hmong digits |
| hmnp | Nyiakeng Puachue Hmong digits |
| java | Javanese digits |
| jpan | Japanese numerals — algorithmic |
| jpanfin | Japanese financial numerals — algorithmic |
| jpanyear | Japanese first-year Gannen numbering for Japanese calendar |
| kali | Kayah Li digits |
| khmr | Khmer digits |
| knda | Kannada digits |
| lana | Tai Tham Hora (secular) digits |
| lanatham | Tai Tham (ecclesiastical) digits |
| laoo | Lao digits |
| latn | Latin digits |
| lepc | Lepcha digits |
| limb | Limbu digits |
| mathbold | Mathematical bold digits |
| mathdbl | Mathematical double-struck digits |
| mathmono | Mathematical monospace digits |
| mathsanb | Mathematical sans-serif bold digits |
| mathsans | Mathematical sans-serif digits |
| mlym | Malayalam digits |
| modi | Modi digits |
| mong | Mongolian digits |
| mroo | Mro digits |
| mtei | Meetei Mayek digits |
| mymr | Myanmar digits |
| mymrshan | Myanmar Shan digits |
| mymrtlng | Myanmar Tai Laing digits |
| native | Native digits |
| newa | Newa digits |
| nkoo | N'Ko digits |
| olck | Ol Chiki digits |
| orya | Oriya digits |
| osma | Osmanya digits |
| rohg | Hanifi Rohingya digits |
| roman | Roman upper case numerals — algorithmic |
| romanlow | Roman lowercase numerals — algorithmic |
| saur | Saurashtra digits |
| shrd | Sharada digits |
| sind | Khudawadi digits |
| sinh | Sinhala Lith digits |
| sora | Sora\_Sompeng digits |
| sund | Sundanese digits |
| takr | Takri digits |
| talu | New Tai Lue digits |
| taml | Tamil numerals — algorithmic |
| tamldec | Modern Tamil decimal digits |
| telu | Telugu digits |
| thai | Thai digits |
| tirh | Tirhuta digits |
| tibt | Tibetan digits |
| traditio | Traditional numerals — may be algorithmic |
| vaii | Vai digits |
| wara | Warang Citi digits |
| wcho | Wancho digits |

Examples
--------

### Obtaining supported numbering systems

If the `Locale` object doesn't have a `numberingSystem` already, `getNumberingSystems()` lists all commonly-used numbering systems for the given `Locale`. For examples of explicitly setting a `numberingSystem`, see `numberingSystem` examples.

```js
const arEG = new Intl.Locale("ar-EG");
console.log(arEG.getNumberingSystems()); // ["arab"]
```

```js
const ja = new Intl.Locale("ja");
console.log(ja.getNumberingSystems()); // ["latn"]
```

Specifications
--------------

| Specification |
| --- |
| Intl Locale Info Proposal # sec-Intl.Locale.prototype.getNumberingSystems |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Locale`
* `Intl.Locale.prototype.numberingSystem`
* Details on the standard Unicode numeral systems


Intl.Locale.prototype.maximize() - JavaScript

Intl.Locale.prototype.maximize()
================================

 The **`maximize()`** method of `Intl.Locale` instances gets the
 most likely values for the language, script, and region of this locale based on
 existing values.

Try it
------

Syntax
------

```js
maximize()
```

### Parameters

None.

### Return value

 A `Intl.Locale` instance whose `baseName` property returns
 the result of the Add Likely Subtags algorithm executed against *`locale.baseName`*.

Description
-----------

 Sometimes, it is convenient to be able to identify the most likely locale language
 identifier subtags based on an incomplete language ID. The Add Likely Subtags
 algorithm gives us this functionality. For instance, given the language ID "en", the
 algorithm would return "en-Latn-US", since English can only be written in the Latin
 script, and is most likely to be used in the United States, as it is the largest
 English-speaking country in the world. This functionality is provided to JavaScript
 programmers via the `maximize()` method. `maximize()` only
 affects the main subtags that comprise the language identifier: language, script, and region subtags.
 Other subtags after the "-u" in the locale identifier are called extension subtags and
 are not affected by the `maximize()` method. Examples of these subtags
 include `hourCycle`,
 `calendar`, and `numeric`.

Examples
--------

### Using maximize

```js
const myLocale = new Intl.Locale("fr", {
  hourCycle: "h12",
  calendar: "gregory",
});
console.log(myLocale.baseName); // Prints "fr"
console.log(myLocale.toString()); // Prints "fr-u-ca-gregory-hc-h12"
const myLocMaximized = myLocale.maximize();

// Prints "fr-Latn-FR". The "Latn" and "FR" tags are added,
// since French is only written in the Latin script and is most likely to be spoken in France.
console.log(myLocMaximized.baseName);

// Prints "fr-Latn-FR-u-ca-gregory-hc-h12".
// Note that the extension tags (after "-u") remain unchanged.
console.log(myLocMaximized.toString());
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-Intl.Locale.prototype.maximize |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Locale`
* `baseName`
* Likely Subtags in the Unicode locale data markup language spec


Intl.Locale.prototype.language - JavaScript

Intl.Locale.prototype.language
==============================

The **`language`** accessor property of `Intl.Locale` instances returns the language associated with this locale.

Description
-----------

Language is one of the core features of a locale. The Unicode specification treats the language identifier of a locale as the language and the region together (to make a distinction between dialects and variations, e.g. British English vs. American English). The `language` property of a `Intl.Locale` returns strictly the locale's language subtag.

Examples
--------

### Setting the language in the locale identifier string argument

In order to be a valid Unicode locale identifier, a string must start with the language subtag. The main argument to the `Intl.Locale()` constructor must be a valid Unicode locale identifier, so whenever the constructor is used, it must be passed an identifier with a language subtag.

```js
const locale = new Intl.Locale("en-Latn-US");
console.log(locale.language); // Prints "en"
```

### Overriding language via the configuration object

While the language subtag must be specified, the `Intl.Locale()` constructor takes a configuration object, which can override the language subtag.

```js
const locale = new Intl.Locale("en-Latn-US", { language: "es" });
console.log(locale.language); // Prints "es"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-Intl.Locale.prototype.language |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Locale`
* Unicode language subtag in the Unicode locale data markup language spec


Intl.Locale.prototype.hourCycle - JavaScript

Intl.Locale.prototype.hourCycle
===============================

The **`hourCycle`** accessor property of `Intl.Locale` instances returns the hour cycle type for this locale.

Description
-----------

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`.

For a list of supported hour cycle types, see `Intl.Locale.prototype.getHourCycles()`.

The set accessor of `hourCycle` is `undefined`. You cannot change this property directly.

Examples
--------

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

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.

```js
const locale = new Intl.Locale("fr-FR-u-hc-h23");
console.log(locale.hourCycle); // "h23"
```

### Adding an hour cycle via the configuration object argument

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.

```js
const locale = new Intl.Locale("en-US", { hourCycle: "h12" });
console.log(locale.hourCycle); // "h12"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-Intl.Locale.prototype.hourCycle |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Locale`
* `Intl.Locale.prototype.getHourCycles()`
* Unicode Hour Cycle Identifier in the Unicode locale data markup language spec


Intl.Locale.prototype.collation - JavaScript

Intl.Locale.prototype.collation
===============================

The **`collation`** accessor property of `Intl.Locale` instances returns the collation type for this locale, which is used to order strings according to the locale's rules.

Description
-----------

Collation is the process of ordering strings of characters. It is used whenever strings must be sorted and placed into a certain order, from search query results to ordering records in a database. While the idea of placing strings in order might seem trivial, the idea of order can vary from region to region and language to language. The `collation` property's value is set at construction time, either through the `co` key of the locale identifier or through the `collation` 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`.

For a list of supported collation types, see `Intl.Locale.prototype.getCollations()`.

The set accessor of `collation` is `undefined`. You cannot change this property directly.

Examples
--------

Like other locale subtags, the collation type can be added to the `Intl.Locale` object via the locale string, or a configuration object argument to the constructor.

### Adding a collation type via the locale string

In the Unicode locale string spec, collation 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 collation type can be added to the initial locale identifier string that is passed into the `Intl.Locale()` constructor. To add the collation type, first add the `-u` extension to the string. Next, add the `-co` extension to indicate that you are adding a collation type. Finally, add the collation type to the string.

```js
const locale = new Intl.Locale("zh-Hant-u-co-zhuyin");
console.log(locale.collation); // "zhuyin"
```

### Adding a collation type via the configuration object argument

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

```js
const locale = new Intl.Locale("zh-Hant", { collation: "zhuyin" });
console.log(locale.collation); // "zhuyin"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-Intl.Locale.prototype.collation |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Locale`
* `Intl.Locale.prototype.getCollations()`


Intl.Locale.prototype.getCollations() - JavaScript

Intl.Locale.prototype.getCollations()
=====================================

The **`getCollations()`** method of `Intl.Locale` instances returns a list of one or more collation types for this locale.

**Note:** In some versions of some browsers, this method was implemented as an accessor property called `collations`. However, because it returns a new array on each access, it is now implemented as a method to prevent the situation of `locale.collations === locale.collations` returning `false`. Check the browser compatibility table for details.

Syntax
------

```js
getCollations()
```

### Parameters

None.

### Return value

An array of strings representing all collation types commonly used for the `Locale`, sorted in alphabetical order, with the `standard` and `search` values always excluded. If the `Locale` already has a `collation`, then the returned array contains that single value.

Below is a list of the supported collation types, adapted from the Unicode collation specification.

### Supported collation types

`big5han`

Pinyin ordering for Latin, big5 charset ordering for CJK characters (for Chinese)

**Warning:** The `big5han` collation type is deprecated, not available in Firefox, Chrome or Edge.

`compat`

A previous version of the ordering, for compatibility (for Arabic)

`dict`

Dictionary style ordering (for Sinhala)

`direct`

Binary code point order

**Warning:** The `direct` collation type has been deprecated. Do not use.

`ducet`

The default Unicode collation element table order

**Warning:** The `ducet` collation type is not available to the Web. Use the `und` locale without a collation type specifier instead. `und` is the collation that is the closest to `ducet`.

`emoji`

Recommended ordering for emoji characters (for the `und` locale)

`eor`

European ordering rules (for the `und` locale)

`gb2312`

Pinyin ordering for Latin, gb2312han charset ordering for CJK characters (for Chinese)

**Warning:** The `gb2312` collation type is deprecated, not available in Firefox, Chrome or Edge.

`phonebk`

Phonebook style ordering (for German)

`phonetic`

Phonetic ordering (sorting based on pronunciation; for Lingala)

`pinyin`

Pinyin ordering for Latin and for CJK characters (for Chinese)

`reformed`

Reformed ordering (formerly for Swedish)

**Warning:** Do not use explicitly. This is the old name for the default ordering for Swedish whose collation naming used to differ from other languages. Since this was the default, request `sv` instead of requesting `sv-u-co-reformed`.

`search`

Special collation type for string search

**Warning:** Do not use as a collation type, since in `Intl.Collator`, this collation is activated via the `"search"` value for the `usage` option. There is currently no API for substring search, so this is currently only good for filtering a list of strings by trying a full-string match of the key against each list item.

`searchjl`

Special collation type for Korean initial consonant search

**Warning:** This collation is not for sorting, even though it is made available through `Intl.Collator` instantiated with usage `"sort"` as opposed to usage `"search"`.

`standard`

Default ordering for each language, except Chinese (and, previously, Swedish)

**Warning:** Do not use explicitly. In general, it's unnecessary to specify this explicitly and specifying this for Swedish is problematic due to the different meaning for Swedish in the past.

`stroke`

Pinyin ordering for Latin, stroke order for CJK characters (for Chinese)

`trad`

Traditional style ordering (such as in Spanish)

`unihan`

Radical-stroke ordering for Han characters (for Chinese, Japanese, and Korean). Pinyin ordering for Latin in the case of Chinese.

**Note:** The `unihan` collation type is not available in Chrome or Edge.

`zhuyin`

Pinyin ordering for Latin, zhuyin order for Bopomofo and CJK characters (for Chinese)

Examples
--------

### Obtaining supported collation types

If the `Locale` object doesn't have a `collation` already, `getCollations()` lists all commonly-used collation types for the given `Locale`. For examples of explicitly setting a `collation`, see `collation` examples.

```js
const locale = new Intl.Locale("zh");
console.log(locale.getCollations()); // ["pinyin", "stroke", "zhuyin", "emoji", "eor"]
```

Specifications
--------------

| Specification |
| --- |
| Intl Locale Info Proposal # sec-Intl.Locale.prototype.getCollations |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Locale`
* `Intl.Locale.prototype.collation`


Intl.Locale.prototype.getHourCycles() - JavaScript

Intl.Locale.prototype.getHourCycles()
=====================================

The **`getHourCycles()`** method of `Intl.Locale` instances returns a list of one or more unique hour cycle identifiers for this locale.

**Note:** In some versions of some browsers, this method was implemented as an accessor property called `hourCycles`. However, because it returns a new array on each access, it is now implemented as a method to prevent the situation of `locale.hourCycles === locale.hourCycles` returning `false`. Check the browser compatibility table for details.

Syntax
------

```js
getHourCycles()
```

### Parameters

None.

### Return value

An array of strings representing all hour cycle types commonly used for the `Locale`, sorted in descending preference. If the `Locale` already has an `hourCycle`, then the returned array contains that single value.

Below is a list of supported hour cycle types.

### Supported hour cycle types

`h12`

Hour system using 1–12; corresponds to 'h' in patterns. The 12 hour clock, with midnight starting at 12:00 am. As used, for example, in the United States.

`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. Mostly used in Japan.

`h24`

Hour system using 1–24; corresponds to 'k' in pattern. The 24 hour clock, with midnight starting at 24:00. Not used anywhere.

Examples
--------

### Obtaining supported hour cycles

If the `Locale` object doesn't have a `hourCycle` already, `getHourCycles()` lists all commonly-used collation types for the given `Locale`. For examples of explicitly setting a `hourCycle`, see `hourCycle` examples.

```js
const arEG = new Intl.Locale("ar-EG");
console.log(arEG.getHourCycles()); // ["h12"]
```

```js
const jaJP = new Intl.Locale("ja-JP");
console.log(jaJP.getHourCycles()); // ["h23"]
```

Specifications
--------------

| Specification |
| --- |
| Intl Locale Info Proposal # sec-Intl.Locale.prototype.getHourCycles |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.Locale`
* `Intl.Locale.prototype.hourCycle`
* Unicode Hour Cycle Identifier in the Unicode locale data markup language spec


Intl.DurationFormat() constructor - JavaScript

Intl.DurationFormat() constructor
=================================

**Experimental:** **This is an experimental technology**
Check the Browser compatibility table carefully before using this in production.

The **`Intl.DurationFormat()`** constructor creates `Intl.DurationFormat` objects.

Syntax
------

```js
new Intl.DurationFormat()
new Intl.DurationFormat(locales)
new Intl.DurationFormat(locales, options)
```

**Note:** `Intl.DurationFormat()` can only be constructed with `new`. Attempting to call it without `new` throws a `TypeError`.

### Parameters

`locales` Optional

A string with a BCP 47 language tag or an `Intl.Locale` instance, or an array of such locale identifiers. For the general form and interpretation of the `locales` argument, see the parameter description on the `Intl` main page.

The following Unicode extension key is allowed:

`nu`

See `numberingSystem`.

This key can also be set with `options` (as listed below). When both are set, the `options` property takes precedence.

`options` Optional

An object containing the following properties, in the order they are retrieved (all of them are optional):

`localeMatcher`

The locale matching algorithm to use. Possible values are `"lookup"` and `"best fit"`; the default is `"best fit"`. For information about this option, see Locale identification and negotiation.

`numberingSystem`

The numbering system to use for number formatting, such as `"arab"`, `"hans"`, `"mathsans"`, and so on. For a list of supported numbering system types, see `Intl.Locale.prototype.getNumberingSystems()`. This option can also be set through the `nu` Unicode extension key; if both are provided, this `options` property takes precedence.

`style`

The style of the formatted duration. Possible values are:

`"long"`

E.g., 1 hour and 50 minutes

`"short"` (default)

E.g., 1 hr, 50 min

`"narrow"`

E.g., 1h 50m

`"digital"`

E.g., 1:50:00

`years`

The style of the formatted years. Possible values are `"long"`, `"short"`, and `"narrow"`; the default is `options.style` if it's not `"digital"`, and `"short"` otherwise.

`yearsDisplay`

Whether to always display years, or only if nonzero. Possible values are `"always"` and `"auto"`; the default is `"auto"` if `years` is unspecified, and `"always"` otherwise.

`months`

The style of the formatted months. Possible values are `"long"`, `"short"`, and `"narrow"`; the default is `options.style` if it's not `"digital"`, and `"short"` otherwise.

`monthsDisplay`

Whether to always display months, or only if nonzero. Possible values are `"always"` and `"auto"`; the default is `"auto"` if `months` is unspecified, and `"always"` otherwise.

`weeks`

The style of the formatted weeks. Possible values are `"long"`, `"short"`, and `"narrow"`; the default is `options.style` if it's not `"digital"`, and `"short"` otherwise.

`weeksDisplay`

Whether to always display weeks, or only if nonzero. Possible values are `"always"` and `"auto"`; the default is `"auto"` if `weeks` is unspecified, and `"always"` otherwise.

`days`

The style of the formatted days. Possible values are `"long"`, `"short"`, and `"narrow"`; the default is `options.style` if it's not `"digital"`, and `"short"` otherwise.

`daysDisplay`

Whether to always display days, or only if nonzero. Possible values are `"always"` and `"auto"`; the default is `"auto"` if `days` is unspecified, and `"always"` otherwise.

`hours`

The style of the formatted hours. Possible values are `"long"`, `"short"`, `"narrow"`, `"numeric"`, and `"2-digit"`; the default is `options.style` if it's not `"digital"`, and `"numeric"` otherwise.

`hoursDisplay`

Whether to always display hours, or only if nonzero. Possible values are `"always"` and `"auto"`; the default is `"auto"` if `hours` is unspecified and `options.style` is not `"digital"`, and `"always"` otherwise.

`minutes`

The style of the formatted minutes.

* If `hours` is `"numeric"` or `"2-digit"`, possible values are `"numeric"` and `"2-digit"`, and `"numeric"` is normalized to `"2-digit"`; the default is `"numeric"`.
* Otherwise, possible values are `"long"`, `"short"`, `"narrow"`, `"numeric"`, and `"2-digit"`; the default is `options.style` if it's not `"digital"`, and `"numeric"` otherwise.

`minutesDisplay`

Whether to always display minutes, or only if nonzero. Possible values are `"always"` and `"auto"`; the default is `"auto"` if `minutes` is unspecified and `options.style` is not `"digital"`, and `"always"` otherwise.

`seconds`

The style of the formatted seconds.

* If `minutes` is `"numeric"` or `"2-digit"`, possible values are `"numeric"` and `"2-digit"`, and `"numeric"` is normalized to `"2-digit"`; the default is `"numeric"`.
* Otherwise, possible values are `"long"`, `"short"`, `"narrow"`, `"numeric"`, and `"2-digit"`; the default is `options.style` if it's not `"digital"`, and `"numeric"` otherwise.

`secondsDisplay`

Whether to always display seconds, or only if nonzero. Possible values are `"always"` and `"auto"`; the default is `"auto"` if `seconds` is unspecified and `options.style` is not `"digital"`, and `"always"` otherwise.

`milliseconds`

The style of the formatted milliseconds.

* If `seconds` is `"numeric"` or `"2-digit"`, the only possible value is `"numeric"`; the default is `"numeric"`.
* Otherwise, possible values are `"long"`, `"short"`, `"narrow"`, and `"numeric"`; the default is `options.style` if it's not `"digital"`, and `"numeric"` otherwise.

`millisecondsDisplay`

Whether to always display milliseconds, or only if nonzero.

* If `seconds` is `"numeric"` or `"2-digit"`, the only possible value is `"auto"`; the default is only `"auto"` when `milliseconds` is unspecified.
* Otherwise, possible values are `"always"` and `"auto"`; the default is `"auto"` if `milliseconds` is unspecified, and `"always"` otherwise.

`microseconds`

The style of the formatted microseconds.

* If `milliseconds` is `"numeric"`, the only possible value is `"numeric"`; the default is `"numeric"`.
* Otherwise, possible values are `"long"`, `"short"`, `"narrow"`, and `"numeric"`; the default is `options.style` if it's not `"digital"`, and `"numeric"` otherwise.

`microsecondsDisplay`

Whether to always display microseconds, or only if nonzero.

* If `milliseconds` is `"numeric"`, the only possible value is `"auto"`; the default is only `"auto"` when `microseconds` is unspecified.
* Otherwise, possible values are `"always"` and `"auto"`; the default is `"auto"` if `microseconds` is unspecified, and `"always"` otherwise.

`nanoseconds`

The style of the formatted nanoseconds.

* If `microseconds` is `"numeric"`, the only possible value is `"numeric"`; the default is `"numeric"`.
* Otherwise, possible values are `"long"`, `"short"`, `"narrow"`, and `"numeric"`; the default is `options.style` if it's not `"digital"`, and `"numeric"` otherwise.

`nanosecondsDisplay`

Whether to always display nanoseconds, or only if nonzero.

* If `microseconds` is `"numeric"`, the only possible value is `"auto"`; the default is only `"auto"` when `nanoseconds` is unspecified.
* Otherwise, possible values are `"always"` and `"auto"`; the default is `"auto"` if `nanoseconds` is unspecified, and `"always"` otherwise.

`fractionalDigits`

Number of how many fractional second digits to display in the output. Possible values are from `0` to `9`; the default is `undefined` (include as many fractional digits as necessary).

### Exceptions

`RangeError`

Thrown if `locales` or `options` contain invalid values.

Description
-----------

For each time segment, an `Intl.NumberFormat` object is constructed under the hood. It uses the following options (see `Intl.NumberFormat()` for details):

* `numberingSystem`: the value of `options.numberingSystem`

When `milliseconds`, `microseconds`, or `nanoseconds` uses the `"numeric"` style, the following options are also used:

* `minimumFractionDigits`: `0` when `options.fractionalDigits` is `undefined`, `options.fractionalDigits` otherwise
* `maximumFractionDigits`: `9` when `options.fractionalDigits` is `undefined`, `options.fractionalDigits` otherwise
* `roundingMode`: `"trunc"`

When the time segment uses the `"2-digit"` style, the following options are also used:

* `minimumIntegerDigits`: `2`

When the time segment uses the `"long"`, `"short"`, or `"narrow"` style, the following options are also used:

* `style`: `"unit"` when `"long"`, `"short"`, or `"narrow"` is specified, `undefined` otherwise
* `unit`: the currently formatted unit (`"years"`, `"days"`, `"nanoseconds"`, etc.)
* `unitDisplay`: the value of the time segment style (`"long"`, `"short"`, or `"narrow"`)
Examples
--------

### Using the Intl.DurationFormat() constructor

```js
const duration = {
  hours: 2,
  minutes: 20,
  seconds: 35,
};

console.log(new Intl.DurationFormat("pt", { style: "long" }).format(duration));
// "2 horas, 20 minutos e 35 segundos"
```

Specifications
--------------

| Specification |
| --- |
| Intl.DurationFormat # sec-intl-durationformat-constructor |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.DurationFormat`
* `Intl.supportedValuesOf()`
* `Intl`


Intl.DurationFormat.prototype.resolvedOptions() - JavaScript

Intl.DurationFormat.prototype.resolvedOptions()
===============================================

**Experimental:** **This is an experimental technology**
Check the Browser compatibility table carefully before using this in production.

The **`resolvedOptions()`** method of `Intl.DurationFormat` instances returns a new object with properties reflecting the locale and date and time formatting options computed during initialization of this `Intl.DurationFormat` object.

Syntax
------

```js
resolvedOptions()
```

### Parameters

None.

### Return value

A new object with properties reflecting the locale and date and time formatting options computed during the initialization of the given `Intl.DateTimeFormat` object.

Description
-----------

The resulting object has the following properties:

`locale`

The BCP 47 language tag for the locale used. If any Unicode extension values were requested in the input BCP 47 language tag that led to this locale, the key-value pairs that were requested and are supported for this locale are included in `locale`.

`style`

One of the strings `"long"`, `"short"`, `"narrow"`, or `"digital"` identifying the duration formatting style used.

`years`

One of the strings `"long"`, `"short"`, or `"narrow"` identifying the formatting style used for the `years` field.

`yearsDisplay`

One of the strings `"auto"` or `"always"` identifying when to display the `years` field.

`months`

One of the strings `"long"`, `"short"`, `and "narrow"` identifying the formatting style used for the `months` field.

`monthsDisplay`

One of the strings `"auto"` or `"always"` identifying when to display the `months` field.

`weeks`

One of the strings `"long"`, `"short"`, `and "narrow"` identifying the formatting style used for the `weeks` field.

`weeksDisplay`

One of the strings `"auto"` or `"always"` identifying when to display the `weeks` field.

`days`

One of the strings `"long"`, `"short"`, and `"narrow"` identifying the formatting style used for the `days` field.

`daysDisplay`

One of the strings `"auto"` or `"always"` identifying when to display the `days` field.

`hours`

One of the strings `"long"`, `"short"`, `"narrow"`, `"2-digit"`, or `"numeric"` identifying the formatting style used for the `hours` field.

`hoursDisplay`

One of the strings `"auto"` or `"always"` identifying when to display the `hours` field.

`minutes`

One of the strings `"long"`, `"short"`, `"narrow"`, `"2-digit"`, or `"numeric"` identifying the formatting style used for the `minutes` field.

`minutesDisplay`

One of the strings `"auto"` or `"always"` identifying when to display the `minutes` field.

`seconds`

One of the strings `"long"`, `"short"`, `"narrow"`, `"2-digit"`, or `"numeric"` identifying the formatting style used for the `seconds` field.

`secondsDisplay`

One of the strings `"auto"` or `"always"` identifying when to display the `seconds` field.

`milliseconds`

One of the strings `"long"`, `"short"`, `"narrow"`, or `"numeric"` identifying the formatting style used for the `milliseconds` field.

`millisecondsDisplay`

One of the strings `"auto"` or `"always"` identifying when to display the `millisecondsDisplay` field.

`microseconds`

One of the strings `"long"`, `"short"`, `"narrow"`, or `"numeric"` identifying the formatting style used for the `microseconds` field.

`microsecondsDisplay`

One of the strings `"auto"` or `"always"` identifying when to display the `microsecondsDisplay` field.

`nanoseconds`

One of the strings `"long"`, `"short"`, `"narrow"`, or `"numeric"` identifying the formatting style used for the `nanoseconds` field.

`nanosecondsDisplay`

One of the strings `"auto"` or `"always"` identifying when to display the `nanosecondsDisplay` field.

`fractionalDigits`

A number, identifying the number of fractional digits used with numeric styles.

`numberingSystem`

The value provided for this property in the options argument, if present, or the value requested using the Unicode extension key `nu` or filled in as a default.

Examples
--------

### Using the resolvedOptions method

```js
const duration = new Intl.DurationFormat("en");
const usedOptions = duration.resolvedOptions();

usedOptions.locale; // "en"
usedOptions.numberingSystem; // "latn"
usedOptions.years; // "long"
usedOptions.yearsDisplay; // "auto"
usedOptions.style; // "long"
```

Specifications
--------------

| Specification |
| --- |
| Intl.DurationFormat # sec-Intl.DurationFormat.prototype.resolvedOptions |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.DurationFormat`
* `Intl.supportedValuesOf()`
* `Intl`


Intl.DurationFormat.prototype.formatToParts() - JavaScript

Intl.DurationFormat.prototype.formatToParts()
=============================================

**Experimental:** **This is an experimental technology**
Check the Browser compatibility table carefully before using this in production.

The **`formatToParts()`** method of `Intl.DurationFormat` instances allows locale-aware formatting of strings produced by `Intl.DurationFormat` formatters.

Syntax
------

```js
formatToParts(duration)
```

### Parameters

`duration` Optional

The duration object to be formatted. It should include some or all of the following properties: `"months"`, `"weeks"`, `"days"`, `"hours"`, `"minutes"`, `"seconds"`, `"milliseconds"`, `"microseconds"`, `"nanoseconds"`.

### Return value

An `Array` of objects containing the formatted duration in parts.

Description
-----------

The `formatToParts()` method is useful for custom formatting of duration objects. It returns an `Array` of objects containing the locale-specific tokens from which it possible to build custom strings while preserving the locale-specific parts. The structure the `formatToParts()` method returns, looks like this:

```js
[
  { type: "integer", value: "7", unit: "hour" },
  { type: "literal", value: " ", unit: "hour" },
  { type: "unit", value: "hr", unit: "hour" },
  { type: "literal", value: ", " },
  { type: "integer", value: "8", unit: "minute" },
  { type: "literal", value: " ", unit: "minute" },
  { type: "unit", value: "min", unit: "minute" },
];
```

Examples
--------

The `formatToParts` method enables locale-aware formatting of strings produced by `DurationFormat` formatters by providing you the string in parts:

```js
const duration = {
  hours: 7,
  minutes: 8,
  seconds: 9,
  milliseconds: 123,
  microseconds: 456,
  nanoseconds: 789,
};

new Intl.DurationFormat("en", { style: "long" }).formatToParts(duration);

// Returned value:
[
  { type: "integer", value: "7", unit: "hour" },
  { type: "literal", value: " ", unit: "hour" },
  { type: "unit", value: "hours", unit: "hour" },
  { type: "literal", value: ", " },
  { type: "integer", value: "8", unit: "minute" },
  { type: "literal", value: " ", unit: "minute" },
  { type: "unit", value: "minutes", unit: "minute" },
  { type: "literal", value: ", " },
  { type: "integer", value: "9", unit: "second" },
  { type: "literal", value: " ", unit: "second" },
  { type: "unit", value: "seconds", unit: "second" },
  { type: "literal", value: ", " },
  { type: "integer", value: "123", unit: "millisecond" },
  { type: "literal", value: " ", unit: "millisecond" },
  { type: "unit", value: "milliseconds", unit: "millisecond" },
  { type: "literal", value: ", " },
  { type: "integer", value: "456", unit: "microsecond" },
  { type: "literal", value: " ", unit: "microsecond" },
  { type: "unit", value: "microseconds", unit: "microsecond" },
  { type: "literal", value: " and " },
  { type: "integer", value: "789", unit: "nanosecond" },
  { type: "literal", value: " ", unit: "nanosecond" },
  { type: "unit", value: "nanoseconds", unit: "nanosecond" },
];
```

Specifications
--------------

| Specification |
| --- |
| Intl.DurationFormat # sec-Intl.DurationFormat.prototype.formatToParts |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.DurationFormat`
* `Intl.supportedValuesOf()`
* `Intl`


Intl.DurationFormat.prototype.format() - JavaScript

Intl.DurationFormat.prototype.format()
======================================

**Experimental:** **This is an experimental technology**
Check the Browser compatibility table carefully before using this in production.

The **`format()`** method of `Intl.DurationFormat` instances formats a duration according to the locale and formatting options of this `Intl.DurationFormat` object.

Syntax
------

```js
format(duration)
```

### Parameters

`duration`

The duration object to be formatted. It should include some or all of the following properties: `months`, `weeks`, `days`, `hours`, `minutes`, `seconds`, `milliseconds`, `microseconds`, `nanoseconds`.

### Return value

A string representing the given `duration` formatted according to the locale and formatting options of this `Intl.DurationFormat` object.

Examples
--------

### Using format()

The following example shows how to create a Duration formatter using the English language.

```js
const duration = {
  years: 1,
  months: 2,
  weeks: 3,
  days: 3,
  hours: 4,
  minutes: 5,
  seconds: 6,
  milliseconds: 7,
  microseconds: 8,
  nanoseconds: 9,
};

// Without options, style defaults to "short"
new Intl.DurationFormat("en").format(duration);
// "1 yr, 2 mths, 3 wks, 3 days, 4 hr, 5 min, 6 sec, 7 ms, 8 μs, 9 ns"

// With style set to "long"
new Intl.DurationFormat("en", { style: "long" }).format(duration);
// "1 year, 2 months, 3 weeks, 3 days, 4 hours, 5 minutes, 6 seconds, 7 milliseconds, 8 microseconds, 9 nanoseconds"

// With style set to "narrow"
new Intl.DurationFormat("en", { style: "narrow" }).format(duration);
// "1y 2mo 3w 3d 4h 5m 6s 7ms 8μs 9ns"
```

### Using format() with different locales and styles

```js
const duration = {
  hours: 1,
  minutes: 46,
  seconds: 40,
};

// With style set to "long" and locale "fr-FR"
new Intl.DurationFormat("fr-FR", { style: "long" }).format(duration);
// "1 heure, 46 minutes et 40 secondes"

// With style set to "short" and locale set to "en"
new Intl.DurationFormat("en", { style: "short" }).format(duration);
// "1 hr, 46 min and 40 sec"

// With style set to "short" and locale set to "pt"
new Intl.DurationFormat("pt", { style: "narrow" }).format(duration);
// "1h 46min 40s"

// With style set to "digital" and locale set to "en"
new Intl.DurationFormat("en", { style: "digital" }).format(duration);
// "1:46:40"

// With style set to "digital", locale set to "en", and hours set to "long"
new Intl.DurationFormat("en", { style: "digital", hours: "long" }).format(
  duration,
);
// "1 hour, 46:40"
```

### Using format() with the fractionalDigits option

```js
const duration = {
  hours: 11,
  minutes: 30,
  seconds: 12,
  milliseconds: 345,
  microseconds: 600,
};

new Intl.DurationFormat("en", { style: "digital" }).format(duration);
// "11:30:12.3456"

new Intl.DurationFormat("en", { style: "digital", fractionalDigits: 5 }).format(
  duration,
);
// "11:30:12.34560"

new Intl.DurationFormat("en", { style: "digital", fractionalDigits: 3 }).format(
  duration,
);
// "11:30:12.346"
```

Specifications
--------------

| Specification |
| --- |
| Intl.DurationFormat # sec-Intl.DurationFormat.prototype.format |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.DurationFormat`
* `Intl.supportedValuesOf()`
* `Intl`


Intl.DurationFormat.supportedLocalesOf() - JavaScript

Intl.DurationFormat.supportedLocalesOf()
========================================

**Experimental:** **This is an experimental technology**
Check the Browser compatibility table carefully before using this in production.

The **`Intl.DurationFormat.supportedLocalesOf()`** static method returns an array containing those of the provided locales that are supported in duration formatting without having to fall back to the runtime's default locale.

Syntax
------

```js
Intl.DurationFormat.supportedLocalesOf(locales)
Intl.DurationFormat.supportedLocalesOf(locales, options)
```

### Parameters

`locales`

A string with a BCP 47 language tag, or an array of such strings. For the general form and interpretation of the `locales` argument, see the parameter description on the `Intl` main page.

`options` Optional

An object that may have the following property:

`localeMatcher`

The locale matching algorithm to use. Possible values are `"lookup"` and `"best fit"`; the default is `"best fit"`. For information about this option, see the Intl page.

### Return value

An array of strings representing a subset of the given locale tags that are supported in duration formatting without having to fall back to the runtime's default locale.

Examples
--------

### Using supportedLocalesOf()

Assuming a runtime that supports Indonesian and German but not Balinese in duration formatting, `supportedLocalesOf` returns the Indonesian and German language tags unchanged, even though `pinyin` collation is neither relevant to duration formatting nor used with Indonesian, and a specialized German for Indonesia is unlikely to be supported. Note the specification of the `"lookup"` algorithm here — a `"best fit"` matcher might decide that Indonesian is an adequate match for Balinese since most Balinese speakers also understand Indonesian, and therefore return the Balinese language tag as well.

```js
const locales = ["ban", "id-u-co-pinyin", "de-ID"];
const options = { localeMatcher: "lookup" };
console.log(Intl.DurationFormat.supportedLocalesOf(locales, options));
// ["id-u-co-pinyin", "de-ID"]
```

Specifications
--------------

| Specification |
| --- |
| Intl.DurationFormat # sec-Intl.DurationFormat.supportedLocalesOf |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.DurationFormat`


Intl.RelativeTimeFormat.supportedLocalesOf() - JavaScript

Intl.RelativeTimeFormat.supportedLocalesOf()
============================================

The **`Intl.RelativeTimeFormat.supportedLocalesOf()`** static method returns an array containing those of the provided locales that are supported in relative time formatting without having to fall back to the runtime's default locale.

Try it
------

Syntax
------

```js
Intl.RelativeTimeFormat.supportedLocalesOf(locales)
Intl.RelativeTimeFormat.supportedLocalesOf(locales, options)
```

### Parameters

`locales`

A string with a BCP 47 language tag, or an array of such strings. For the general form and interpretation of the `locales` argument, see the parameter description on the `Intl` main page.

`options` Optional

An object that may have the following property:

`localeMatcher`

The locale matching algorithm to use. Possible values are `"lookup"` and `"best fit"`; the default is `"best fit"`. For information about this option, see the Intl page.

### Return value

An array of strings representing a subset of the given locale tags that are supported in relative time formatting without having to fall back to the runtime's default locale.

Examples
--------

### Using supportedLocalesOf()

Assuming a runtime that supports Indonesian and German but not Balinese in relative time formatting, `supportedLocalesOf` returns the Indonesian and German language tags unchanged, even though `pinyin` collation is neither relevant to relative time formatting nor used with Indonesian, and a specialized German for Indonesia is unlikely to be supported. Note the specification of the `"lookup"` algorithm here — a `"best fit"` matcher might decide that Indonesian is an adequate match for Balinese since most Balinese speakers also understand Indonesian, and therefore return the Balinese language tag as well.

```js
const locales = ["ban", "id-u-co-pinyin", "de-ID"];
const options = { localeMatcher: "lookup" };
console.log(Intl.RelativeTimeFormat.supportedLocalesOf(locales, options));
// ["id-u-co-pinyin", "de-ID"]
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-Intl.RelativeTimeFormat.supportedLocalesOf |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.RelativeTimeFormat`


Intl.RelativeTimeFormat.prototype.formatToParts() - JavaScript

Intl.RelativeTimeFormat.prototype.formatToParts()
=================================================

The **`formatToParts()`** method of `Intl.RelativeTimeFormat` instances returns an `Array` of objects representing the relative time format in parts that can be used for custom locale-aware formatting.

Try it
------

Syntax
------

```js
formatToParts(value, unit)
```

### Parameters

`value`

Numeric value to use in the internationalized relative time message.

`unit`

Unit to use in the relative time internationalized message. Possible values are: `"year"`, `"quarter"`, `"month"`, `"week"`, `"day"`, `"hour"`, `"minute"`, `"second"`. Plural forms are also permitted.

### Return value

An `Array` of objects containing the formatted relative time in parts.

Description
-----------

The `Intl.RelativeTimeFormat.prototype.formatToParts` method is a version of the format method which it returns an array of objects which represent "parts" of the object, separating the formatted number into its constituent parts and separating it from other surrounding text. These objects have two properties: type a `NumberFormat` formatToParts type, and value, which is the String which is the component of the output. If a "part" came from `NumberFormat`, it will have a unit property which indicates the unit being formatted; literals which are part of the larger frame will not have this property.

Examples
--------

### Using formatToParts

```js
const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });

// Format relative time using the day unit
rtf.formatToParts(-1, "day");
// [{ type: "literal", value: "yesterday"}]

rtf.formatToParts(100, "day");
// [
// { type: "literal", value: "in " },
// { type: "integer", value: "100", unit: "day" },
// { type: "literal", value: " days" }
// ]
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-Intl.RelativeTimeFormat.prototype.formatToParts |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.RelativeTimeFormat`


Intl.RelativeTimeFormat.prototype.resolvedOptions() - JavaScript

Intl.RelativeTimeFormat.prototype.resolvedOptions()
===================================================

The **`resolvedOptions()`** method of `Intl.RelativeTimeFormat` instances returns a new object with properties reflecting the locale and relative time formatting options computed during initialization of this `Intl.RelativeTimeFormat` object.

Try it
------

Syntax
------

```js
resolvedOptions()
```

### Parameters

None.

### Return value

A new object with properties reflecting the locale and number formatting options computed during the initialization of the given `Intl.RelativeTimeFormat` object.

Description
-----------

The resulting object has the following properties:

`locale`

The BCP 47 language tag for the locale actually used. If any Unicode extension values were requested in the input BCP 47 language tag that led to this locale, the key-value pairs that were requested and are supported for this locale are included in `locale`.

`style`

The length of the internationalized message. Possible values are:

* `"long"` (default, e.g., `in 1 month`)
* `"short"` (e.g., `in 1 mo.`),
* or `"narrow"` (e.g., `in 1 mo.`). The narrow style could be similar to the short style for some locales.

`numeric`

The format of output message. Possible values are:

* `"always"` (default, e.g., `1 day ago`),
* or `"auto"` (e.g., `yesterday`). The `"auto"` value allows to not always have to use numeric values in the output.

`numberingSystem`

The value requested using the Unicode extension key `"nu"` or filled in as a default.

Examples
--------

### Using the resolvedOptions() method

```js
const de = new Intl.RelativeTimeFormat("de-DE");
const usedOptions = de.resolvedOptions();

usedOptions.locale; // "de-DE"
usedOptions.style; // "long"
usedOptions.numeric; // "always"
usedOptions.numberingSystem; // "latn"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-intl.relativetimeformat.prototype.resolvedoptions |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.RelativeTimeFormat`


Intl.RelativeTimeFormat.prototype.format() - JavaScript

Intl.RelativeTimeFormat.prototype.format()
==========================================

The **`format()`** method of `Intl.RelativeTimeFormat` instances formats a `value` and `unit` according to the locale and formatting options of this `Intl.RelativeTimeFormat` object.

Try it
------

Syntax
------

```js
format(value, unit)
```

### Parameters

`value`

Numeric value to use in the internationalized relative time message.

`unit`

Unit to use in the relative time internationalized message. Possible values are: `"year"`, `"quarter"`, `"month"`, `"week"`, `"day"`, `"hour"`, `"minute"`, `"second"`. Plural forms are also permitted.

### Return value

A string representing the given `value` and `unit` formatted according to the locale and formatting options of this `Intl.RelativeTimeFormat` object.

Examples
--------

### Basic format usage

The following example shows how to create a relative time formatter using the English language.

```js
// Create a relative time formatter in your locale
// with default values explicitly passed in.
const rtf = new Intl.RelativeTimeFormat("en", {
  localeMatcher: "best fit", // other values: "lookup"
  numeric: "always", // other values: "auto"
  style: "long", // other values: "short" or "narrow"
});

// Format relative time using negative value (-1).
rtf.format(-1, "day"); // "1 day ago"

// Format relative time using positive value (1).
rtf.format(1, "day"); // "in 1 day"
```

### Using the auto option

If `numeric:auto` option is passed, it will produce the string `yesterday`, `today`, or `tomorrow` instead of `1 day ago`, `in 0 days`, or `in 1 day`. This allows to not always have to use numeric values in the output.

```js
// Create a relative time formatter in your locale
// with numeric: "auto" option value passed in.
const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });

// Format relative time using negative value (-1).
rtf.format(-1, "day"); // "yesterday"

rtf.format(0, "day"); // "today"

// Format relative time using positive day unit (1).
rtf.format(1, "day"); // "tomorrow"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-Intl.RelativeTimeFormat.prototype.format |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.RelativeTimeFormat`


Intl.RelativeTimeFormat() constructor - JavaScript

Intl.RelativeTimeFormat() constructor
=====================================

The **`Intl.RelativeTimeFormat()`** constructor creates `Intl.RelativeTimeFormat` objects.

Syntax
------

```js
new Intl.RelativeTimeFormat()
new Intl.RelativeTimeFormat(locales)
new Intl.RelativeTimeFormat(locales, options)
```

**Note:** `Intl.RelativeTimeFormat()` can only be constructed with `new`. Attempting to call it without `new` throws a `TypeError`.

### Parameters

`locales` Optional

A string with a BCP 47 language tag or an `Intl.Locale` instance, or an array of such locale identifiers. For the general form and interpretation of the `locales` argument, see the parameter description on the `Intl` main page.

The following Unicode extension key is allowed:

`nu`

See `numberingSystem`.

This key can also be set with `options` (as listed below). When both are set, the `options` property takes precedence.

`options` Optional

An object containing the following properties, in the order they are retrieved (all of them are optional):

`localeMatcher`

The locale matching algorithm to use. Possible values are `"lookup"` and `"best fit"`; the default is `"best fit"`. For information about this option, see Locale identification and negotiation.

`numberingSystem`

The numbering system to use for number formatting, such as `"arab"`, `"hans"`, `"mathsans"`, and so on. For a list of supported numbering system types, see `Intl.Locale.prototype.getNumberingSystems()`. This option can also be set through the `nu` Unicode extension key; if both are provided, this `options` property takes precedence.

`style`

The style of the formatted relative time. Possible values are:

`"long"` (default)

E.g., "in 1 month"

`"short"`

E.g., "in 1 mo."

`"narrow"`

E.g., "in 1 mo.". The narrow style could be similar to the short style for some locales.

`numeric`

Whether to use numeric values in the output. Possible values are `"always"` and `"auto"`; the default is `"always"`. When set to `"auto"`, the output may use more idiomatic phrasing such as `"yesterday"` instead of `"1 day ago"`.

### Exceptions

`RangeError`

Thrown if `locales` or `options` contain invalid values.

Examples
--------

### Basic format usage

The following example shows how to create a relative time formatter using the English language.

```js
// Create a relative time formatter in your locale
// with default values explicitly passed in.
const rtf = new Intl.RelativeTimeFormat("en", {
  localeMatcher: "best fit", // other values: "lookup"
  numeric: "always", // other values: "auto"
  style: "long", // other values: "short" or "narrow"
});

// Format relative time using negative value (-1).
rtf.format(-1, "day"); // "1 day ago"

// Format relative time using positive value (1).
rtf.format(1, "day"); // "in 1 day"
```

### Using the auto option

If `numeric:auto` option is passed, it will produce the string `yesterday` or `tomorrow` instead of `1 day ago` or `in 1 day`. This allows to not always have to use numeric values in the output.

```js
// Create a relative time formatter in your locale
// with numeric: "auto" option value passed in.
const rtf = new Intl.RelativeTimeFormat("en", { numeric: "auto" });

// Format relative time using negative value (-1).
rtf.format(-1, "day"); // "yesterday"

// Format relative time using positive day unit (1).
rtf.format(1, "day"); // "tomorrow"
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Internationalization API Specification # sec-intl-relativetimeformat-constructor |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `Intl.RelativeTimeFormat`
* `Intl`
* `Intl.RelativeTimeFormat` on v8.dev (2018)