• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.intl (Internationalization)
2
3The **intl** module provides basic i18n capabilities, such as time and date formatting, number formatting, and string sorting, through the standard i18n APIs defined in ECMA 402.
4The [i18n](js-apis-i18n.md) module provides enhanced i18n capabilities through supplementary interfaces that are not defined in ECMA 402. It works with the intl module to provide a complete suite of i18n capabilities.
5
6>  **NOTE**
7>
8>  - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
9>
10>  - The APIs of this module conform to the [Common Locale Data Repository (CLDR)](https://cldr.unicode.org) internationalization database. The processing result may change with CLDR evolution. API version 12 corresponds to [CLDR 42](https://cldr.unicode.org/index/downloads/cldr-42). For details about data changes, visit the official website.
11>
12>  - Since API version 11, some APIs of this module are supported in ArkTS widgets.
13>
14>  - Since API version 12, the APIs of this module are supported in atomic services.
15
16
17## Modules to Import
18
19```ts
20import { intl } from '@kit.LocalizationKit';
21```
22
23## Locale
24
25### Attributes
26
27**Widget capability**: Since API version 11, this feature is supported in ArkTS widgets.
28
29**Atomic service API**: This API can be used in atomic services since API version 12.
30
31**System capability**: SystemCapability.Global.I18n
32
33| Name             | Type     | Mandatory  | Description                                      |
34| --------------- | ------- | -------- | ---------------------------------------- |
35| language        | string  | Yes   | Language associated with the locale, for example, **zh**. The value complies with the ISO 639 standard.|
36| script          | string  | Yes   | Script type of the language, for example, **Hans**. The value complies with the Unicode ISO 15924 standard.|
37| region          | string  | Yes   | Country or region associated with the locale, for example, **CN**. The value complies with the ISO 3166 standard.|
38| baseName        | string  | Yes   | Basic information about the locale, which consists of the language, script, and region, for example, **zh-Hans-CN**. |
39| caseFirst       | string  | Yes   | Whether case is taken into account for the locale's collation rules. The value can be:<br>"upper",&nbsp;"lower", or &nbsp;"false".<br>For details about their meanings, see Table 1 in [Sorting by Local Habits ](../../internationalization/i18n-sorting-local.md).|
40| calendar        | string  | Yes   | Calendar for the locale. The value can be:<br>The value can be any of the following: **buddhist**, **chinese**, **coptic**, **dangi**, **ethioaa**, **ethiopic**, **gregory**, **hebrew**, **indian**, **islamic**, **islamic-umalqura**, **islamic-tbla**, **islamic-civil**, **islamic-rgsa**, **iso8601**, **japanese**, **persian**, **roc**, or **islamicc**.<br>For details about their meanings, see Table 1 in [Calendar Setting](../../internationalization/i18n-calendar.md).|
41| collation       | string  | Yes   | Collation rules for the locale. The value can be:<br>The value can be any of the following: **big5han**, **compat**, **dict**, **direct**, **ducet**, **eor**, **gb2312**, **phonebk**, **phonetic**, **pinyin**, **reformed**, **searchjl**, **stroke**, **trad**, **unihan**, or **zhuyin**.<br>For details about their meanings, see Table 1 in [Sorting by Local Habits ](../../internationalization/i18n-sorting-local.md).|
42| hourCycle       | string  | Yes   | Time system for the locale. The value can be:<br>"h11", "h12", "h23", or "h24".<br>For details about their display effects, see Table 5 in [Date and Time Formatting](../../internationalization/i18n-time-date.md).|
43| numberingSystem | string  | Yes   | Numbering system for the locale. The value can be:<br>**adlm**, **ahom**, **arab**, **arabext**, **bali**, **beng**, **bhks**, **brah**, **cakm**, **cham**, **deva**, **diak**, **fullwide**, **gong**, **gonm**, **gujr**, **guru**, **hanidec**, **hmng**, **hmnp**, **java**, **kali**, **khmr**, **knda**, **lana**, **lanatham**, **laoo**, **latn**, **lepc**, **limb**, **mathbold**, **mathdbl**, **mathmono**, **mathsanb**, **mathsans**, **mlym**, **modi**, **mong**, **mroo**, **mtei**, **mymr**, **mymrshan**, **mymrtlng**, **newa**, **nkoo**, **olck**, **orya**, **osma**, **rohg**, **saur**, **segment**, **shrd**, **sind**, **sinh**, **sora**, **sund**, **takr**, **talu**, **tamldec**, **telu**, **thai**, **tibt**, **tirh**, **vaii**, **wara**, or **wcho**.|
44| numeric         | boolean | Yes   | Wether to use special sorting rules for digits. The value **true** means to use special sorting rules for digits, and the value **false** means the opposite.<br>The default value is **false**.                     |
45
46### constructor<sup>8+</sup>
47
48constructor()
49
50Creates a **Locale** object.
51
52**Widget capability**: Since API version 11, this feature is supported in ArkTS widgets.
53
54**Atomic service API**: This API can be used in atomic services since API version 12.
55
56**System capability**: SystemCapability.Global.I18n
57
58**Example**
59  ```ts
60  // When creating a **Locale** object, the default constructor uses the current locale of the system.
61  let locale = new intl.Locale();
62  // Return the current system locale.
63  let localeID = locale.toString();
64  ```
65
66### constructor
67
68constructor(locale: string, options?: LocaleOptions)
69
70Creates a **Locale** object.
71
72**Widget capability**: Since API version 11, this feature is supported in ArkTS widgets.
73
74**Atomic service API**: This API can be used in atomic services since API version 12.
75
76**System capability**: SystemCapability.Global.I18n
77
78**Parameters**
79
80| Name                 | Type                              | Mandatory  | Description                          |
81| -------------------- | -------------------------------- | ---- | ---------------------------- |
82| locale               | string                           | Yes   | A string containing locale information, including the language, optional script, and region.<br>The locale can any or all of the preceding information.|
83| options             | [LocaleOptions](#localeoptions) | No   | Options for creating the **Locale** object.|
84
85**Example**
86  ```ts
87  // Create a Locale object named zh-CN.
88  let locale = new intl.Locale("zh-CN");
89  let localeID = locale.toString(); // localeID = "zh-CN"
90  ```
91
92
93### toString
94
95toString(): string
96
97Obtains the string that represents a **Locale** object.
98
99**Widget capability**: Since API version 11, this feature is supported in ArkTS widgets.
100
101**Atomic service API**: This API can be used in atomic services since API version 12.
102
103**System capability**: SystemCapability.Global.I18n
104
105**Return value**
106
107| Type    | Description         |
108| ------ | ----------- |
109| string | String that represents the **Locale** object.|
110
111**Example**
112  ```ts
113  // Create a Locale object named en-GB.
114  let locale = new intl.Locale("en-GB");
115  let localeID = locale.toString(); // localeID = "en-GB"
116  ```
117
118### maximize
119
120maximize(): Locale
121
122Maximizes information of a **Locale** object. If the script and country/region information is missing, add the information.
123
124**Widget capability**: Since API version 11, this feature is supported in ArkTS widgets.
125
126**Atomic service API**: This API can be used in atomic services since API version 12.
127
128**System capability**: SystemCapability.Global.I18n
129
130**Return value**
131
132| Type               | Description        |
133| ----------------- | ---------- |
134| [Locale](#locale) | **Locale** object with the script and country/region information.|
135
136**Example**
137  ```ts
138  // Create a Locale object named zh.
139  let locale = new intl.Locale("zh");
140  // Complete the script and region of the Locale object.
141  let maximizedLocale = locale.maximize();
142  let localeID = maximizedLocale.toString(); // localeID = "zh-Hans-CN"
143
144  // Create a Locale object named en-US.
145  locale = new intl.Locale("en-US");
146  // Complete the script of the Locale object.
147  maximizedLocale = locale.maximize();
148  localeID = maximizedLocale.toString(); // localeID = "en-Latn-US"
149  ```
150
151
152### minimize
153
154minimize(): Locale
155
156Minimizes information of the **Locale** object. If the script and country/region information is present, delete the information.
157
158**Widget capability**: Since API version 11, this feature is supported in ArkTS widgets.
159
160**Atomic service API**: This API can be used in atomic services since API version 12.
161
162**System capability**: SystemCapability.Global.I18n
163
164**Return value**
165
166| Type               | Description        |
167| ----------------- | ---------- |
168| [Locale](#locale) | **Locale** object without the script or country/region information.|
169
170**Example**
171  ```ts
172  // Create a Locale object named zh-Hans-CN.
173  let locale = new intl.Locale("zh-Hans-CN");
174  // Remove the script and region of the Locale object.
175  let minimizedLocale = locale.minimize();
176  let localeID = minimizedLocale.toString(); // localeID = "zh"
177
178  // Create a Locale object named en-US.
179  locale = new intl.Locale("en-US");
180  // Remove the region of the Locale object.
181  minimizedLocale = locale.minimize();
182  localeID = minimizedLocale.toString(); // localeID = "en"
183  ```
184
185## LocaleOptions
186
187Options for initializing the **Locale** object. Since API version 9, the **LocaleOptions** attribute is changed from mandatory to optional.
188
189**Widget capability**: Since API version 11, this feature is supported in ArkTS widgets.
190
191**Atomic service API**: This API can be used in atomic services since API version 12.
192
193**System capability**: SystemCapability.Global.I18n
194
195| Name             | Type     | Mandatory  |  Description                                      |
196| --------------- | ------- | ---- |---------------------------------------- |
197| calendar        | string  | No  |Calendar parameter. The value can be:<br>"buddhist", "chinese", "coptic", "dangi", "ethioaa", "ethiopic", "gregory", "hebrew", "indian", "islamic", "islamic-umalqura", "islamic-tbla", "islamic-civil", "islamic-rgsa", "iso8601", "japanese", "persian", "roc", or "islamicc".|
198| collation       | string  | No    |Collation parameter. The value can be:<br>"big5han", "compat", "dict", "direct", "ducet", "emoji", "eor", "gb2312", "phonebk", "phonetic", "pinyin", "reformed	**search**, **searchjl**, **standard**, **stroke**, **trad**, **unihan**, **zhuyin**.|
199| hourCycle       | string  | No    |Hour cycle. The value can be:<br>"h11",&nbsp;"h12",&nbsp;"h23", or &nbsp;"h24".|
200| numberingSystem | string  | No    |Numbering system. The value can be:<br>**adlm**, **ahom**, **arab**, **arabext**, **bali**, **beng**, **bhks**, **brah**, **cakm**, **cham**, **deva**, **diak**, **fullwide**, **gong**, **gonm**, **gujr**, **guru**, **hanidec**, **hmng**, **hmnp**, **java**, **kali**, **khmr**, **knda**, **lana**, **lanatham**, **laoo**, **latn**, **lepc**, **limb**, **mathbold**, **mathdbl**, **mathmono**, **mathsanb**, **mathsans**, **mlym**, **modi**, **mong**, **mroo**, **mtei**, **mymr**, **mymrshan**, **mymrtlng**, **newa**, **nkoo**, **olck**, **orya**, **osma**, **rohg**, **saur**, **segment**, **shrd**, **sind**, **sinh**, **sora**, **sund**, **takr**, **talu**, **tamldec**, **telu**, **thai**, **tibt**, **tirh**, **vaii**, **wara**, or **wcho**.|
201| numeric         | boolean | No    | Wether to use special sorting rules for digits. The value **true** means to use special sorting rules for digits, and the value **false** means the opposite. The default value is **false**.                              |
202| caseFirst       | string  | No    | Whether upper case or lower case is sorted first. The value can be:<br>"upper",&nbsp;"lower", or &nbsp;"false".|
203
204>  **NOTE**
205>
206>  - For details about **calendar**, see Table 1 in [Calendar Setting](../../internationalization/i18n-calendar.md).
207>
208>  - For details about **hourCycle**, see Table 5 in [Date and Time Formatting](../../internationalization/i18n-time-date.md).
209>
210>  - For details about **caseFirst** and **collation**, see Table 1 in [Sorting by Local Habits ](../../internationalization/i18n-sorting-local.md).
211
212## DateTimeFormat
213
214### constructor<sup>8+</sup>
215
216constructor()
217
218Creates a **DateTimeOptions** object for the specified locale.
219
220**Widget capability**: Since API version 11, this feature is supported in ArkTS widgets.
221
222**Atomic service API**: This API can be used in atomic services since API version 12.
223
224**System capability**: SystemCapability.Global.I18n
225
226**Example**
227  ```ts
228  // Use the current system locale to create a DateTimeFormat object.
229  let datefmt= new intl.DateTimeFormat();
230  ```
231
232### constructor
233
234constructor(locale: string | Array&lt;string&gt;, options?: DateTimeOptions)
235
236Creates a **DateTimeOptions** object for the specified locale.
237
238**Widget capability**: Since API version 11, this feature is supported in ArkTS widgets.
239
240**Atomic service API**: This API can be used in atomic services since API version 12.
241
242**System capability**: SystemCapability.Global.I18n
243
244**Parameters**
245
246| Name                 | Type                                  | Mandatory  | Description                          |
247| -------------------- | ------------------------------------ | ---- | ---------------------------- |
248| locale               | string \| Array&lt;string&gt;        | Yes   | A string containing locale information, including the language, optional script, and region.<br>The locale can any or all of the preceding information.|
249| options              | [DateTimeOptions](#datetimeoptions) | No   | Options for creating the **DateTimeOptions** object.<br>If no options are set, the default values of **year**, **month**, and **day** are **numeric**.|
250
251**Example**
252  ```ts
253  // Use locale zh-CN to create a DateTimeFormat object. Set dateStyle to full and timeStyle to medium.
254  let datefmt= new intl.DateTimeFormat("zh-CN", { dateStyle: 'full', timeStyle: 'medium' });
255
256  // Use the locale list ["ban**, **zh"] to create a DateTimeFormat object. Because ban is an invalid locale ID, locale zh is used to create the DateTimeFormat object.
257  let datefmt= new intl.DateTimeFormat(["ban", "zh"], { dateStyle: 'full', timeStyle: 'medium' });
258  ```
259
260### format
261
262format(date: Date): string
263
264Formats the date and time.
265
266**Widget capability**: Since API version 11, this feature is supported in ArkTS widgets.
267
268**Atomic service API**: This API can be used in atomic services since API version 12.
269
270**System capability**: SystemCapability.Global.I18n
271
272**Parameters**
273
274| Name | Type  | Mandatory  | Description     |
275| ---- | ---- | ---- | ------- |
276| date | Date | Yes   | Date and time. Note: The month starts from **0**. For example, **0** indicates January.|
277
278**Return value**
279
280| Type    | Description          |
281| ------ | ------------ |
282| string | A string containing the formatted date and time.|
283
284**Example**
285  ```ts
286  let date = new Date (2021, 11, 17, 3, 24, 0); // The date and time is 2021.12.17 03:24:00.
287  // Use locale en-GB to create a DateTimeFormat object.
288  let datefmt = new intl.DateTimeFormat("en-GB");
289  let formattedDate = datefmt.format(date); // formattedDate "17/12/2021"
290
291  // Use locale en-GB to create a DateTimeFormat object. Set dateStyle to full and timeStyle to medium.
292  datefmt = new intl.DateTimeFormat("en-GB", { dateStyle: 'full', timeStyle: 'medium' });
293  formattedDate = datefmt.format(date); // formattedDate "Friday, 17 December 2021 at 03:24:00"
294  ```
295
296### formatRange
297
298formatRange(startDate: Date, endDate: Date): string
299
300Formats date and time ranges.
301
302**Widget capability**: Since API version 11, this feature is supported in ArkTS widgets.
303
304**Atomic service API**: This API can be used in atomic services since API version 12.
305
306**System capability**: SystemCapability.Global.I18n
307
308**Parameters**
309
310| Name      | Type  | Mandatory  | Description      |
311| --------- | ---- | ---- | -------- |
312| startDate | Date | Yes   | Start date and time. Note: The month starts from **0**. For example, **0** indicates January.|
313| endDate   | Date | Yes   | End date and time. Note: The month starts from **0**. For example, **0** indicates January.|
314
315**Return value**
316
317| Type    | Description            |
318| ------ | -------------- |
319| string | A string containing the formatted date and time ranges.|
320
321**Example**
322  ```ts
323  let startDate = new Date(2021, 11, 17, 3, 24, 0); // The date and time is 2021.12.17 03:24:00.
324  let endDate = new Date(2021, 11, 18, 3, 24, 0);
325  // Use locale en-GB to create a DateTimeFormat object.
326  let datefmt = new intl.DateTimeFormat("en-GB");
327  let formattedDateRange = datefmt.formatRange(startDate, endDate); // formattedDateRange = "17/12/2021 - 18/12/2021"
328  ```
329
330### resolvedOptions
331
332resolvedOptions(): DateTimeOptions
333
334Obtains the options for creating a **DateTimeOptions** object.
335
336**Widget capability**: Since API version 11, this feature is supported in ArkTS widgets.
337
338**Atomic service API**: This API can be used in atomic services since API version 12.
339
340**System capability**: SystemCapability.Global.I18n
341
342**Return value**
343
344| Type                                  | Description                           |
345| ------------------------------------ | ----------------------------- |
346| [DateTimeOptions](#datetimeoptions) | Options for the **DateTimeOptions** object.|
347
348**Example**
349  ```ts
350  let datefmt = new intl.DateTimeFormat("en-GB", { dateStyle: 'full', timeStyle: 'medium' });
351  // Obtain the options of the DateTimeFormat object.
352  let options = datefmt.resolvedOptions();
353  let dateStyle = options.dateStyle; // dateStyle = "full"
354  let timeStyle = options.timeStyle; // timeStyle = "medium"
355  ```
356
357
358## DateTimeOptions
359
360Defines the options for a **DateTimeOptions** object. Since API version 9, the **DateTimeOptions** attribute is changed from mandatory to optional.
361
362**Widget capability**: Since API version 11, this feature is supported in ArkTS widgets.
363
364**Atomic service API**: This API can be used in atomic services since API version 12.
365
366**System capability**: SystemCapability.Global.I18n
367
368| Name             | Type     | Mandatory  | Description                                      |
369| --------------- | ------- | ---- |  ---------------------------------------- |
370| locale          | string  | No   |Locale, for example, **zh-Hans-CN**.          |
371| dateStyle       | string  | No    |Date display format. The value can be:<br>"long",&nbsp;"short",&nbsp;"medium",&nbsp;"full", or &nbsp;"auto".<br>For details about their display effects, see Table 1 in [Date and Time Formatting](../../internationalization/i18n-time-date.md).|
372| timeStyle       | string  | No    |Time display format. The value can be:<br>"long",&nbsp;"short",&nbsp;"medium",&nbsp;"full", or &nbsp;"auto".<br>For details about their display effects, see Table 2 in [Date and Time Formatting](../../internationalization/i18n-time-date.md).|
373| hourCycle       | string  | No    |Hour cycle. The value can be:<br>"h11",&nbsp;"h12",&nbsp;"h23", or &nbsp;"h24".<br>For details about the display effect when **dateStyle** or **timeStyle** is not set, see Table 5 in [Date and Time Formatting](../../internationalization/i18n-time-date.md).<br>For details about the display effect when **dateStyle** or **timeStyle** is set, see Table 6 in [Date and Time Formatting](../../internationalization/i18n-time-date.md).|
374| timeZone        | string  | No    |Time zone in use. The value is a valid IANA time zone ID.                     |
375| numberingSystem | string  | No    |Numbering system. The value can be:<br>**adlm**, **ahom**, **arab**, **arabext**, **bali**, **beng**, **bhks**, **brah**, **cakm**, **cham**, **deva**, **diak**, **fullwide**, **gong**, **gonm**, **gujr**, **guru**, **hanidec**, **hmng**, **hmnp**, **java**, **kali**, **khmr**, **knda**, **lana**, **lanatham**, **laoo**, **latn**, **lepc**, **limb**, **mathbold**, **mathdbl**, **mathmono**, **mathsanb**, **mathsans**, **mlym**, **modi**, **mong**, **mroo**, **mtei**, **mymr**, **mymrshan**, **mymrtlng**, **newa**, **nkoo**, **olck**, **orya**, **osma**, **rohg**, **saur**, **segment**, **shrd**, **sind**, **sinh**, **sora**, **sund**, **takr**, **talu**, **tamldec**, **telu**, **thai**, **tibt**, **tirh**, **vaii**, **wara**, or **wcho**.|
376| hour12          | boolean | No    | Whether to use the 12-hour clock. The value **true** means to use the 12-hour clock, and the value **false** means the opposite.<br>If both **hour12** and **hourCycle** are set, **hourCycle** does not take effect.<br>If **hour12** and **hourCycle** are not set and the 24-hour clock is turned on, the default value of **hour12** is **false**.|
377| weekday         | string  | No    | Week display format. The value can be:<br>"long",&nbsp;"short",&nbsp;"narrow", or &nbsp;"auto".<br>For details about their display effects, see Table 4 in [Date and Time Formatting](../../internationalization/i18n-time-date.md).|
378| era             | string  | No    | Epoch display format. The value can be:<br>"long",&nbsp;"short",&nbsp;"narrow", or &nbsp;"auto".<br>For details about their display effects, see Table 9 in [Date and Time Formatting](../../internationalization/i18n-time-date.md).|
379| year            | string  | No    | Year display format. The value can be:<br>"numeric" or &nbsp;"2-digit".<br>For details about their display effects, see Table 3 in [Date and Time Formatting](../../internationalization/i18n-time-date.md). |
380| month           | string  | No   | Month display format. The value can be:<br>"numeric",&nbsp;"2-digit",&nbsp;"long",&nbsp;"short",&nbsp;"narrow", or &nbsp;"auto".<br>For details about their display effects, see Table 6 in [Date and Time Formatting](../../internationalization/i18n-time-date.md).|
381| day             | string  | No    | Day display format. The value can be:<br>"numeric" or &nbsp;"2-digit". |
382| hour            | string  | No    | Hour display format. The value can be:<br>"numeric" or &nbsp;"2-digit". |
383| minute          | string  | No    | Minute display format. The value can be:<br>"numeric" or &nbsp;"2-digit". |
384| second          | string  | No    | Second display format. The value can be:<br>"numeric" or &nbsp;"2-digit". |
385| timeZoneName    | string  | No    | Localized representation of a time zone name. The value can be:<br>"long",&nbsp;"short", or &nbsp;"auto".<br>For details about their display effects, see Table 8 in [Date and Time Formatting](../../internationalization/i18n-time-date.md).  |
386| dayPeriod       | string  | No    | Time period display format. The value can be:<br>"long",&nbsp;"short",&nbsp;"narrow", or &nbsp;"auto".<br>For details about their display effects, see Table 10 in [Date and Time Formatting](../../internationalization/i18n-time-date.md).|
387| localeMatcher   | string  | No    | Locale matching algorithm. The value can be:<br>- "lookup": exact match.<br>- "best fit": best match.|
388| formatMatcher   | string  | No    | Format matching algorithm. The value can be:<br>- "basic": exact match.<br>- "best fit": best match.|
389
390## NumberFormat
391
392### constructor<sup>8+</sup>
393
394constructor()
395
396Creates a **NumberFormat** object for the specified locale.
397
398**Atomic service API**: This API can be used in atomic services since API version 12.
399
400**System capability**: SystemCapability.Global.I18n
401
402**Example**
403  ```ts
404  // Use the current system locale to create a NumberFormat object.
405  let numfmt = new intl.NumberFormat();
406  ```
407
408
409### constructor
410
411constructor(locale: string | Array&lt;string&gt;, options?: NumberOptions)
412
413Creates a **NumberFormat** object for the specified locale.
414
415**Atomic service API**: This API can be used in atomic services since API version 12.
416
417**System capability**: SystemCapability.Global.I18n
418
419**Parameters**
420
421| Name                 | Type                              | Mandatory  | Description                          |
422| -------------------- | -------------------------------- | ---- | ---------------------------- |
423| locale               | string \| Array&lt;string&gt;    | Yes   | A string containing locale information, including the language, optional script, and region.|
424| options              | [NumberOptions](#numberoptions) | No   | Options for creating the **NumberFormat** object.              |
425
426**Example**
427  ```ts
428  // Use locale en-GB to create a NumberFormat object. Set style to decimal and notation to scientific.
429  let numfmt = new intl.NumberFormat("en-GB", {style:'decimal', notation:"scientific"});
430  ```
431
432### format
433
434format(number: number): string
435
436Formats a number.
437
438**Atomic service API**: This API can be used in atomic services since API version 12.
439
440**System capability**: SystemCapability.Global.I18n
441
442**Parameters**
443
444| Name   | Type    | Mandatory  | Description  |
445| ------ | ------ | ---- | ---- |
446| number | number | Yes   | Number to be formatted.|
447
448**Return value**
449
450| Type    | Description        |
451| ------ | ---------- |
452| string | Formatted number.|
453
454
455**Example**
456  ```ts
457  // Use locale list ["en-GB**, **zh"] to create a NumberFormat object. Because en-GB is a valid locale ID, it is used to create the NumberFormat object.
458  let numfmt : intl.NumberFormat = new intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"});
459  let formattedNumber : string = numfmt.format(1223); // formattedNumber = 1.223E3
460  let options : intl.NumberOptions = {
461    roundingPriority: "lessPrecision",
462    maximumFractionDigits: 3,
463    maximumSignificantDigits: 3
464  }
465  let numberFmt : intl.NumberFormat = new intl.NumberFormat("en", options);
466  let result : string = numberFmt.format(1.23456); // result = 1.23
467  ```
468
469### formatRange<sup>18+</sup>
470
471formatRange(startRange: number, endRange: number): string
472
473Formats number ranges.
474
475**Atomic service API**: This API can be used in atomic services since API version 18.
476
477**System capability**: SystemCapability.Global.I18n
478
479**Parameters**
480
481| Name   | Type    | Mandatory  | Description  |
482| ------ | ------ | ---- | ---- |
483| startRange | number | Yes   | Start number.|
484| endRange | number | Yes   | End number.|
485
486**Return value**
487
488| Type    | Description        |
489| ------ | ---------- |
490| string | Formatted number range.|
491
492
493**Example**
494  ```ts
495  let numfmt : intl.NumberFormat = new intl.NumberFormat("en-US", {style:'unit', unit:"meter"});
496  let formattedRange : string = numfmt.formatRange(0, 3); // formattedRange: 0–3 m
497  ```
498
499
500### resolvedOptions
501
502resolvedOptions(): NumberOptions
503
504Obtains the options for creating a **NumberFormat** object.
505
506**Atomic service API**: This API can be used in atomic services since API version 12.
507
508**System capability**: SystemCapability.Global.I18n
509
510**Return value**
511
512| Type                              | Description                         |
513| -------------------------------- | --------------------------- |
514| [NumberOptions](#numberoptions) | Options for creating the **NumberFormat** object.|
515
516
517**Example**
518  ```ts
519  let numfmt = new intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"});
520  // Obtain the options of the NumberFormat object.
521  let options = numfmt.resolvedOptions();
522  let style = options.style; // style = decimal
523  let notation = options.notation; // notation = scientific
524  ```
525
526## NumberOptions
527
528Options for creating the **NumberFormat** object. Since API version 9, the **NumberOptions** attribute is changed from mandatory to optional.
529
530**System capability**: SystemCapability.Global.I18n
531
532| Name                      | Type     | Mandatory  |  Description                                      |
533| ------------------------ | ------- | ---- |  ---------------------------------------- |
534| locale                   | string  | No   | Locale, for example, **zh-Hans-CN**.<br>The default value of **locale** is the system locale.<br>**Atomic service API**: This API can be used in atomic services since API version 12.              |
535| currency                 | string  | No   | Currency unit. The value must comply with the [ISO-4217 standard](https://www.iso.org/iso-4217-currency-codes.html), for example, EUR, CNY, and USD.<br>From API version 12, a three-digit number is supported, for example, **978**, **156**, or **840**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.   |
536| currencySign             | string  | No   | Currency unit symbol. The value can be **standard** or **accounting**.<br>The default value is **standard**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
537| currencyDisplay          | string  | No   | Currency display mode. The value can be **symbol**, **narrowSymbol**, **code**, or **name**.<br>The default value is **symbol**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
538| unit                     | string  | No   | Unit name, for example, **meter**, **inch**, or **hectare**.<br>The combination units supported since API version 18 are as follows: beat-per-minute, body-weight-per-second, breath-per-minute, foot-per-hour, jump-rope-per-minute, meter-per-hour, milliliter-per-minute-per-kilogram, rotation-per-minute, step-per-minute, and stroke-per-minute.<br>**Atomic service API**: This API can be used in atomic services since API version 12.      |
539| unitDisplay              | string  | No   | Display format of units. The value can be **long**, **short**, or **narrow**.<br>The default value is **short**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
540| unitUsage<sup>8+</sup>   | string  | No   | Application scenario of units. The value can be any of the following: "default**, **area-land-agricult**, **area-land-commercl**, **area-land-residntl**, **length-person**, **length-person-small**, **length-rainfall**, **length-road**, **length-road-small**, **length-snowfall**, **length-vehicle**, **length-visiblty**, **length-visiblty-small**, **length-person-informal**, **length-person-small-informal**, **length-road-informal**, **speed-road-travel**, **speed-wind**, **temperature-person**, **temperature-weather**, **volume-vehicle-fuel**, **elapsed-time-second**, **size-file-byte**, or **size-shortfile-byte**.<br>The default value is **default**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
541| signDisplay              | string  | No   | Number sign display format. The value can be:<br>- "auto": automatically determines whether to display the plus or minus sign.<br>- "never": do not display the plus or minus sign.<br>- "always": always displays the plus or minus sign.<br>- "exceptZero": displays the plus or minus sign for all values except 0.<br>The default value is **auto**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
542| compactDisplay           | string  | No   | Compact display format. The value can be **long** or **short**.<br>The default value is **short**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.     |
543| notation                 | string  | No   | Number formatting specification. The value can be **standard**, **scientific**, **engineering**, or **compact**.<br>The default value is **standard**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
544| localeMatcher            | string  | No   | Locale matching algorithm. The value can be **lookup** or **best fit**.<br>The default value is **best fit**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
545| style                    | string  | No   | Number display format. The value can be **decimal**, **currency**, **percent**, or **unit**.<br>The default value is **decimal**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
546| numberingSystem          | string  | No   | Numbering system. The value can be:<br>The value can be any of the following: **adlm**, **ahom**, **arab**, **arabext**, **bali**, **beng**, **bhks**, **brah**, **cakm**, **cham**, **deva**, **diak**, **fullwide**, **gong**, **gonm**, **gujr**, **guru**, **hanidec**, **hmng**, **hmnp**, **java**, **kali**, **khmr**, **knda**, **lana**, **lanatham**, **laoo**, **latn**, **lepc**, **limb**, **mathbold**, **mathdbl**, **mathmono**, **mathsanb**, **mathsans**, **mlym**, **modi**, **mong**, **mroo**, **mtei**, **mymr**, **mymrshan**, **mymrtlng**, **newa**, **nkoo**, **olck**, **orya**, **osma**, **rohg**, **saur**, **segment**, **shrd**, **sind**, **sinh**, **sora**, **sund**, **takr**, **talu**, **tamldec**, **telu**, **thai**, **tibt**, **tirh**, **vaii**, **wara**, or **wcho**. The default value is the default numbering system of the specified locale.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
547| useGrouping              | boolean | No   | Whether to enable grouping for display. The value **true** means to enable grouping for display, and the value **false** means the opposite. The default value is **auto**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                                 |
548| minimumIntegerDigits     | number  | No   | Minimum number of digits allowed in the integer part of a number. The value ranges from **1** to **21**.<br>The default value is **1**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                 |
549| minimumFractionDigits    | number  | No   | Minimum number of digits in the fraction part of a number. The value ranges from **0** to **20**.<br>The default value is **0**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                 |
550| maximumFractionDigits    | number  | No   | Maximum number of digits in the fraction part of a number. The value ranges from **1** to **21**.<br>The default value is **3**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                 |
551| minimumSignificantDigits | number  | No   | Minimum number of the least significant digits. The value ranges from **1** to **21**.<br>The default value is **1**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                 |
552| maximumSignificantDigits | number  | No   | Maximum number of the least significant digits. The value ranges from **1** to **21**.<br>The default value is **21**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.                 |
553| roundingPriority<sup>18+</sup>   | string  | No   | Rounding priority used when both the maximum number of fraction digits and the maximum number of valid digits are set. The value can be **auto**, **morePrecision**, or **lessPrecision**. The value **morePrecision** indicates that the maximum number of fraction digits is used. The value **lessPrecision** indicates that the maximum number of valid digits is used.<br>The default value is **auto**.<br>**Atomic service API**: This API can be used in atomic services since API version 18.                 |
554| roundingIncrement<sup>18+</sup>  | number  | No   | Rounding increment. The value can be **1**, **2**, **5**, **10**, **20**, **25**, **50**, **100**, **200**, **250**, **500**, **1000**, **2000**, **2500**, or **5000**.<br>The default value is **1**.<br>**Atomic service API**: This API can be used in atomic services since API version 18.                 |
555| roundingMode<sup>18+</sup>       | string  | No   | Rounding mode. The value can be:<br>- "ceil": rounding up.<br>- "floor": rounding down.<br>- "expand": rounding away from 0.<br>- "trunc": rounding toward 0.<br>- "halfCeil": half-rounding up; that is, rounding up when the decimal number is greater than or equal to half of the increment, and rounding down otherwise.<br>- "halfFloor": half-rounding down; that is, rounding up when the decimal number is greater than half of the increment, and rounding down otherwise.<br>- "halfExpand": half-rounding away from 0; that is, rounding away from 0 when the decimal number is greater than or equal to half of the increment, and rounding toward 0 otherwise.<br>- "halfTrunc": half-rounding toward 0; that is, rounding away from 0 when the decimal number is greater than half of the increment, and rounding toward 0 otherwise.<br>- "halfEven": half-rounding to the nearest even number; that is, rounding away from 0 when the decimal number is greater than half of the increment, rounding toward 0 when the decimal number is less than half of the increment, and rounding to the nearest even number when the decimal number is exactly half of the increment.<br>The default value is **halfExpand**.<br>**Atomic service API**: This API can be used in atomic services since API version 18.|
556
557>  **NOTE**
558>
559>  - For details about the meaning or display effect of different values, see [Number and Unit of Measurement Formatting](../../internationalization/i18n-numbers-weights-measures.md).
560
561## Collator<sup>8+</sup>
562
563### constructor<sup>8+</sup>
564
565constructor()
566
567Creates a **Collator** object.
568
569**Atomic service API**: This API can be used in atomic services since API version 12.
570
571**System capability**: SystemCapability.Global.I18n
572
573**Example**
574  ```ts
575  // Use the system locale to create a Collator object.
576  let collator = new intl.Collator();
577  ```
578
579
580### constructor<sup>8+</sup>
581
582constructor(locale: string | Array&lt;string&gt;, options?: CollatorOptions)
583
584Creates a **Collator** object.
585
586**Atomic service API**: This API can be used in atomic services since API version 12.
587
588**System capability**: SystemCapability.Global.I18n
589
590**Parameters**
591
592| Name                 | Type                                  | Mandatory  | Description                          |
593| -------------------- | ------------------------------------ | ---- | ---------------------------- |
594| locale               | string \| Array&lt;string&gt;        | Yes   | A string containing locale information, including the language, optional script, and region. |
595| options              | [CollatorOptions](#collatoroptions8) | No   | Options for creating a **Collator** object.      |
596
597**Example**
598  ```ts
599  // Use locale zh-CN to create a Collator object. Set localeMatcher to lookup and usage to sort.
600  let collator = new intl.Collator("zh-CN", {localeMatcher: "lookup", usage: "sort"});
601  ```
602
603
604### compare<sup>8+</sup>
605
606compare(first: string, second: string): number
607
608Compares two strings based on the specified collation rules.
609
610**Atomic service API**: This API can be used in atomic services since API version 12.
611
612**System capability**: SystemCapability.Global.I18n
613
614**Parameters**
615
616| Name   | Type    | Mandatory  | Description          |
617| ------ | ------ | ---- | ------------ |
618| first  | string | Yes   | First string to compare. |
619| second | string | Yes   | Second string to compare.|
620
621**Return value**
622
623| Type    | Description                                      |
624| ------ | ---------------------------------------- |
625| number | Comparison result.<br>- If the value is a negative number, the first string comes before the second string.<br>- If the value is **0**, the first and second strings are in the same sequence.<br>- If the value is a positive number, the first string is comes after the second string.|
626
627**Example**
628  ```ts
629  // Use locale en-GB to create a Collator object.
630  let collator = new intl.Collator("en-GB");
631  // Compare the sequence of the first and second strings.
632  let compareResult = collator.compare("first", "second"); // compareResult = -1
633  ```
634
635
636### resolvedOptions<sup>8+</sup>
637
638resolvedOptions(): CollatorOptions
639
640Obtains the options for creating a **Collator** object.
641
642**Atomic service API**: This API can be used in atomic services since API version 12.
643
644**System capability**: SystemCapability.Global.I18n
645
646**Return value**
647
648| Type                                  | Description               |
649| ------------------------------------ | ----------------- |
650| [CollatorOptions](#collatoroptions8) | Options for creating a **Collator** object.|
651
652**Example**
653  ```ts
654  let collator = new intl.Collator("zh-Hans", { usage: 'sort', ignorePunctuation: true });
655  // Obtain the options of the Collator object.
656  let options = collator.resolvedOptions();
657  let usage = options.usage; // usage = "sort"
658  let ignorePunctuation = options.ignorePunctuation; // ignorePunctuation = true
659  ```
660
661
662## CollatorOptions<sup>8+</sup>
663
664Defines the options for creating a **Collator** object.
665
666Since API version 9, the attributes in **CollatorOptions** are optional.
667
668**Atomic service API**: This API can be used in atomic services since API version 12.
669
670**System capability**: SystemCapability.Global.I18n
671
672| Name               | Type     | Mandatory  | Description                                      |
673| ----------------- | ------- | ---- | ---------------------------------------- |
674| localeMatcher     | string  | No   | Locale matching algorithm. The value can be **lookup** or **best fit**.<br>The default value is **best fit**.|
675| usage             | string  | No   | Whether the comparison is for sorting or for searching. The value can be **sort** or **search**.<br>The default value is **sort**.       |
676| sensitivity       | string  | No   | Differences in the strings that lead to non-zero return values. The value can be **base**, **accent**, **case**, or **letiant**.<br>The default value is **variant**.|
677| ignorePunctuation | boolean | No   | Whether to ignore punctuation. The value **true** means to ignore punctuation, and the value **false** means the opposite.<br>The default value is **false**.       |
678| collation         | string  | No   | Collation rule.<br>The value can be any of the following: **big5han**, **compat**, **dict**, **direct**, **ducet**, **eor**, **gb2312**, **phonebk**, **phonetic**, **pinyin**, **reformed**, **searchjl**, **stroke**, **trad**, **unihan**, or **zhuyin**.<br>The default value is **default**.|
679| numeric           | boolean | No   | Whether to use numeric collation. The value **true** means to use numeric collation, and the value **false** means the opposite.<br>The default value is **false**.         |
680| caseFirst         | string  | No   | Whether upper case or lower case is sorted first. The value can be **upper**, **lower**, or **false**.<br>The default value is **false**.|
681
682
683>  **NOTE**
684>
685>  - For details about the meanings of different field values, see [Sorting by Local Habits](../../internationalization/i18n-sorting-local.md).
686
687
688## PluralRules<sup>8+</sup>
689
690### constructor<sup>8+</sup>
691
692constructor()
693
694Creates a **PluralRules** object to obtain the singular-plural type of numbers.
695
696**Atomic service API**: This API can be used in atomic services since API version 12.
697
698**System capability**: SystemCapability.Global.I18n
699
700**Example**
701  ```ts
702  // Use the system locale to create a PluralRules object.
703  let pluralRules = new intl.PluralRules();
704  ```
705
706
707### constructor<sup>8+</sup>
708
709constructor(locale: string | Array&lt;string&gt;, options?: PluralRulesOptions)
710
711Creates a **PluralRules** object to obtain the singular-plural type of numbers.
712
713**Atomic service API**: This API can be used in atomic services since API version 12.
714
715**System capability**: SystemCapability.Global.I18n
716
717**Parameters**
718
719| Name                 | Type                                      | Mandatory  | Description                          |
720| -------------------- | ---------------------------------------- | ---- | ---------------------------- |
721| locale               | string \| Array&lt;string&gt;            | Yes   | A string containing locale information, including the language, optional script, and region.|
722| options              | [PluralRulesOptions](#pluralrulesoptions8) | No   | Options for creating a **PluralRules** object.      |
723
724**Example**
725  ```ts
726  // Use locale zh-CN to create a PluralRules object. Set localeMatcher to lookup and type to cardinal.
727  let pluralRules= new intl.PluralRules("zh-CN", {"localeMatcher": "lookup", "type": "cardinal"});
728  ```
729
730### select<sup>8+</sup>
731
732select(n: number): string
733
734Obtains a string that represents the singular-plural type of the specified number.
735
736**Atomic service API**: This API can be used in atomic services since API version 12.
737
738**System capability**: SystemCapability.Global.I18n
739
740**Parameters**
741
742| Name | Type    | Mandatory  | Description          |
743| ---- | ------ | ---- | ------------ |
744| n    | number | Yes   | Number for which the singular-plural type is to be obtained.|
745
746**Return value**
747
748| Type    | Description                                      |
749| ------ | ---------------------------------------- |
750| string | Singular-plural type. The value can be any of the following: **zero**, **one**, **two**, **few**, **many**, **others**.<br>For details about the meanings of different values, see [Language Plural Rules](https://www.unicode.org/cldr/charts/45/supplemental/language_plural_rules.html).|
751
752**Example**
753  ```ts
754  // Use locale zh-Hans to create a PluralRules object.
755  let zhPluralRules = new intl.PluralRules("zh-Hans");
756  // Determine the singular-plural type corresponding to number 1 in locale zh-Hans.
757  let plural = zhPluralRules.select(1); // plural = other
758
759  // Use locale en-US to create a PluralRules object.
760  let enPluralRules = new intl.PluralRules("en-US");
761  // Determine the singular-plural type corresponding to number 1 in locale en-US.
762  plural = enPluralRules.select(1); // plural = one
763  ```
764
765
766## PluralRulesOptions<sup>8+</sup>
767
768Defines the options for creating a **PluralRules** object. Since API version 9, the **PluralRulesOptions** attribute is changed from mandatory to optional.
769
770**Atomic service API**: This API can be used in atomic services since API version 12.
771
772**System capability**: SystemCapability.Global.I18n
773
774| Name                      | Type    | Readable  | Writable  | Description                                      |
775| ------------------------ | ------ | ---- | ---- | ---------------------------------------- |
776| localeMatcher            | string | Yes   | Yes   | Locale matching algorithm. The value can be **lookup** or **best fit**.<br>The default value is **best fit**.|
777| type                     | string | Yes   | Yes   | Collation type. The value can be **cardinal** or **ordinal**.<br>The default value is **cardinal**.<br>The value **cardinal** indicates a cardinal number and the value **ordinal** indicates an ordinal number. |
778| minimumIntegerDigits     | number | Yes   | Yes   | Minimum number of digits allowed in the integer part of a number. The value ranges from **1** to **21**.<br>The default value is **1**.                 |
779| minimumFractionDigits    | number | Yes   | Yes   | Minimum number of digits in the fraction part of a number. The value ranges from **0** to **20**.<br>The default value is **0**.                 |
780| maximumFractionDigits    | number | Yes   | Yes   | Maximum number of digits in the fraction part of a number. The value ranges from **1** to **21**.<br>The default value is **3**.                 |
781| minimumSignificantDigits | number | Yes   | Yes   | Minimum number of the least significant digits. The value ranges from **1** to **21**.<br>The default value is **1**.                 |
782| maximumSignificantDigits | number | Yes   | Yes   | Maximum number of the least significant digits. The value ranges from **1** to **21**.<br>The default value is **21**.               |
783
784
785## RelativeTimeFormat<sup>8+</sup>
786
787### constructor<sup>8+</sup>
788
789constructor()
790
791Creates a **RelativeTimeFormat** object.
792
793**Atomic service API**: This API can be used in atomic services since API version 12.
794
795**System capability**: SystemCapability.Global.I18n
796
797**Example**
798  ```ts
799  // Use the system locale to create a RelativeTimeFormat object.
800  let relativetimefmt = new intl.RelativeTimeFormat();
801  ```
802
803
804### constructor<sup>8+</sup>
805
806constructor(locale: string | Array&lt;string&gt;, options?: RelativeTimeFormatInputOptions)
807
808Creates a **RelativeTimeFormat** object.
809
810**Atomic service API**: This API can be used in atomic services since API version 12.
811
812**System capability**: SystemCapability.Global.I18n
813
814**Parameters**
815
816| Name                 | Type                                      | Mandatory  | Description                          |
817| -------------------- | ---------------------------------------- | ---- | ---------------------------- |
818| locale               | string \| Array&lt;string&gt;            | Yes   | A string containing locale information, including the language, optional script, and region.|
819| options              | [RelativeTimeFormatInputOptions](#relativetimeformatinputoptions8) | No   | Options for creating a **RelativeTimeFormat** object.    |
820
821**Example**
822  ```ts
823  // Use locale zh-CN to create a RelativeTimeFormat object. Set localeMatcher to lookup, numeric to always, and style to long.
824  let relativeTimeFormat = new intl.RelativeTimeFormat("zh-CN", {"localeMatcher": "lookup", "numeric": "always", "style": "long"});
825  ```
826
827
828### format<sup>8+</sup>
829
830format(value: number, unit: string): string
831
832Formats the value and unit based on the specified locale and formatting options.
833
834**Atomic service API**: This API can be used in atomic services since API version 12.
835
836**System capability**: SystemCapability.Global.I18n
837
838**Parameters**
839
840| Name  | Type    | Mandatory  | Description                                      |
841| ----- | ------ | ---- | ---------------------------------------- |
842| value | number | Yes   | Value to format.                             |
843| unit  | string | Yes   | Unit of the relative time.<br>The value can be any of the following: **year**, **quarter**, month**, **week**, **day**, **hour**, **minute**, or **second**.|
844
845**Return value**
846
847| Type    | Description        |
848| ------ | ---------- |
849| string | Relative time after formatting.|
850
851**Example**
852  ```ts
853  // Use locale zh-CN to create a RelativeTimeFormat object.
854  let relativetimefmt = new intl.RelativeTimeFormat("zh-CN");
855  // Obtain the localized representation (in unit of quarter) of number 3 in locale zh-CN.
856  let formatResult = relativetimefmt.format(3, "quarter"); // formatResult = "3 quarters later"
857  ```
858
859
860### formatToParts<sup>8+</sup>
861
862formatToParts(value: number, unit: string): Array&lt;object&gt;
863
864Custom relative time for the specified locale.
865
866**Atomic service API**: This API can be used in atomic services since API version 12.
867
868**System capability**: SystemCapability.Global.I18n
869
870**Parameters**
871
872| Name  | Type    | Mandatory  | Description                                      |
873| ----- | ------ | ---- | ---------------------------------------- |
874| value | number | Yes   | Value to format.                             |
875| unit  | string | Yes   | Unit of the relative time.<br>The value can be any of the following: **year**, **quarter**, month**, **week**, **day**, **hour**, **minute**, or **second**.|
876
877**Return value**
878
879| Type                 | Description                         |
880| ------------------- | --------------------------- |
881| Array&lt;object&gt; | Object array of the relative time format.|
882
883**Example**
884  ```ts
885  // Use locale en to create a RelativeTimeFormat object. Set numeric to auto.
886  let relativetimefmt = new intl.RelativeTimeFormat("en", {"numeric": "auto"});
887  let parts = relativetimefmt.formatToParts(10, "seconds"); // parts = [ {type: "literal", value: "in"}, {type: "integer", value: 10, unit: "second"}, {type: "literal", value: "seconds"} ]
888  ```
889
890
891### resolvedOptions<sup>8+</sup>
892
893resolvedOptions(): RelativeTimeFormatResolvedOptions
894
895Obtains the formatting options for **RelativeTimeFormat** objects.
896
897**Atomic service API**: This API can be used in atomic services since API version 12.
898
899**System capability**: SystemCapability.Global.I18n
900
901**Return value**
902
903| Type                                      | Description                               |
904| ---------------------------------------- | --------------------------------- |
905| [RelativeTimeFormatResolvedOptions](#relativetimeformatresolvedoptions8) | Formatting options for **RelativeTimeFormat** objects.|
906
907**Example**
908  ```ts
909  // Use locale en-GB to create a RelativeTimeFormat object.
910  let relativetimefmt= new intl.RelativeTimeFormat("en-GB", { style: "short" });
911  // Obtain the options of the RelativeTimeFormat object.
912  let options = relativetimefmt.resolvedOptions();
913  let style = options.style; // style = "short"
914  ```
915
916
917## RelativeTimeFormatInputOptions<sup>8+</sup>
918
919Defines the options for creating a **RelativeTimeFormat** object.
920
921Since API version 9, the attributes in **RelativeTimeFormatInputOptions** are optional.
922
923**Atomic service API**: This API can be used in atomic services since API version 12.
924
925**System capability**: SystemCapability.Global.I18n
926
927| Name           | Type    | Mandatory  |Description                                      |
928| ------------- | ------ | ---- | ---------------------------------------- |
929| localeMatcher | string | No   | Locale matching algorithm. The value can be **lookup** or **best fit**.<br>The default value is **best fit**.|
930| numeric       | string | No   | Format of the output message. The value can be **always** or **auto**.<br>The default value is **always**.     |
931| style         | string | No   | Length of an internationalized message. The value can be **long**, **short**, or **narrow**.<br>The default value is **long**.|
932
933> **NOTE**
934>
935> For details about the display effects of **numeric** and **style**, see [Date and Time Formatting](../../internationalization/i18n-time-date.md#relative-time-formatting).
936
937## RelativeTimeFormatResolvedOptions<sup>8+</sup>
938
939Represents the properties of a **RelativeTimeFormat** object.
940
941**Atomic service API**: This API can be used in atomic services since API version 12.
942
943**System capability**: SystemCapability.Global.I18n
944
945| Name             | Type    | Mandatory  |Description                                      |
946| --------------- | ------ | ---- | ---------------------------------------- |
947| locale          | string | Yes   | A string containing locale information, including the language, optional script, and region.            |
948| numeric         | string | Yes   | Format of the output message. The value can be **always** or **auto**.     |
949| style           | string | Yes   | Length of an internationalized message. The value can be **long**, **short**, or **narrow**.|
950| numberingSystem | string | Yes   | Numbering system. The value can be:<br>**adlm**, **ahom**, **arab**, **arabext**, **bali**, **beng**, **bhks**, **brah**, **cakm**, **cham**, **deva**, **diak**, **fullwide**, **gong**, **gonm**, **gujr**, **guru**, **hanidec**, **hmng**, **hmnp**, **java**, **kali**, **khmr**, **knda**, **lana**, **lanatham**, **laoo**, **latn**, **lepc**, **limb**, **mathbold**, **mathdbl**, **mathmono**, **mathsanb**, **mathsans**, **mlym**, **modi**, **mong**, **mroo**, **mtei**, **mymr**, **mymrshan**, **mymrtlng**, **newa**, **nkoo**, **olck**, **orya**, **osma**, **rohg**, **saur**, **segment**, **shrd**, **sind**, **sinh**, **sora**, **sund**, **takr**, **talu**, **tamldec**, **telu**, **thai**, **tibt**, **tirh**, **vaii**, **wara**, or **wcho**.|
951
952> **NOTE**
953>
954> For details about the display effects of **numeric** and **style**, see [Date and Time Formatting](../../internationalization/i18n-time-date.md#relative-time-formatting).
955