Locales class
📖 Description
The Locales
class holds locale information and contains functions to format dates and numbers. The Locales
instance is accessible through the locale
property of the L10n
module.
🗃️ Fields
🏷️ country
Retrieves the country for the current active locale.
Type
string
🏷️ countryCode
Retrieves the country code for the current active locale.
Type
string
🏷️ countryNative
Retrieves the native country name for the current active locale.
Type
string
🏷️ direction
Retrieves the text direction for the current active locale.
Type
"ltr" | "rtl"
🏷️ domain
Retrieves the domain for the current locale.
Type
string
🏷️ identifier
Retrieves the locale identifier string.
Type
string
🏷️ language
Retrieves the language for the current active locale.
Type
string
🏷️ languageNative
Retrieves the language in the native language for the current active locale.
Type
string
🏷️ locale
Retrieves the locale information for the current active locale.
Type
▶️ Methods
🔧 dateFull
Formats to a localized full date string (for example, Wednesday, March 23, 2022
).
Signature
dateFull(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the date/time to format (defaults to the current date/time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized date string.
🔧 dateLong
Formats to a localized long date string (for example, March 23, 2022
).
Signature
dateLong(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the date/time to format (defaults to the current date/time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized date string.
🔧 dateMedium
Formats to a localized medium date string (for example, Mar 23, 2022
).
Signature
dateMedium(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the date/time to format (defaults to the current date/time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized date string.
🔧 dateShort
Formats to a localized short date string (for example, 3/23/22
).
Signature
dateShort(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the date/time to format (defaults to the current date/time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized date string.
🔧 dateTime
Formats a date/time to a localized string.
Signature
dateTime(format: string, time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
format | string | No | Specifies the format to use, using the CLDR date/time formatting style. The following variables are available: - y / yyyy : Specifies the full 4-digit year;- yy : Specifies the 2-digit year;- M : Specifies the month number;- MM : Specifies the month number with a minimum of 2 digits;- MMM : Specifies the month as an abbreviated string (e.g. Jan );- MMMM : Specifies the month as a full string (e.g. January );- MMMMM : Specifies the month as a narrow (e.g. J );- LLL : Specifies the month as an abbreviated nominative string (e.g. Jan );- LLLL : Specifies the month as a full nominative string (e.g. January );- LLLLL : Specifies the month as a narrow nominative string (e.g. J );- d : Specifies the day of the month;- dd : Specifies the day of the month with a minimum of 2 digits;- E : Specifies the day of the week;- EE : Specifies the day of the week as a string (e.g. Su );- EEE : Specifies the day of the week as an abbreviated string (e.g. Sun );- EEEE : Specifies the day of the week as a full string (e.g. Sunday );- EEEEE : Specifies the day of the week as a narrow string (e.g. S );- cc : Specifies the day of the week as a nominative string (e.g. Su );- ccc : Specifies the day of the week as an abbreviated nominative string (e.g. Sun );- cccc : Specifies the day of the week as a full nominative string (e.g. Sunday );- ccccc : Specifies the day of the week as a narrow nominative string (e.g. S );- H : Specifies the number of hours in 24-hour format;- HH : Specifies the number of hours in 24-hour format with a minimum of 2 digits;- h : Specifies the number of hours in 12-hour format;- hh : Specifies the number of hours in 12-hour format with a minimum of 2 digits;- a : Specifies the AM or PM hour suffix;- m : Specifies the number of minutes;- mm : Specifies the number of minutes with a minimum of 2 digits;- s : Specifies the number of seconds;- ss : Specifies the number of seconds with a minimum of 2 digits;- S : Specifies the number of milliseconds;- SSS : Specifies the number of milliseconds with a minimum of 3 digits. |
time | number | Yes | Specifies the date/time to format (defaults to the current date/time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized date string.
🔧 dateTimeFull
Formats to a localized full date/time string (for example, Wednesday, March 23, 2022 at 4:38:47 PM
).
Signature
dateTimeFull(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized date/time string.
🔧 dateTimeLong
Formats to a localized long date/time string (for example, March 23, 2022 at 4:38:38 PM
).
Signature
dateTimeLong(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized date/time string.
🔧 dateTimeMedium
Formats to a localized medium date/time string (for example, Mar 23, 2022, 4:38:29 PM
).
Signature
dateTimeMedium(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized date/time string.
🔧 dateTimeShort
Formats to a localized short date/time string (for example, 3/23/22, 4:38 PM
).
Signature
dateTimeShort(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized date/time string.
🔧 number
Formats a number to a localized string by inserting thousands and decimal separators while taking rounding into account.
Signature
number(n: number | string, precision?: number | "auto", thousands?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
n | number | string | No | Specifies the number to format. |
precision | number | "auto" | Yes | Specifies the precision (set it to auto to allow floating point numbers with automatic precision detection). |
thousands | boolean | Yes | Specifies if thousands separators should be inserted (default is false ). |
Return value
Returns the formatted number as a localized string.
🔧 timeFull
Formats to a localized full time string (for example, 4:39:45 PM
).
Signature
timeFull(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized time string.
🔧 timeLong
Formats to a localized long time string (for example, 4:39:18 PM
).
Signature
timeLong(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized time string.
🔧 timeMedium
Formats to a localized medium time string (for example, 4:39:08 PM
).
Signature
timeMedium(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized time string.
🔧 timeShort
Formats to a localized short time string (for example, 4:38 PM
).
Signature
timeShort(time?: number, UTC?: boolean): string
Parameters
Name | Type | Optional | Description |
---|---|---|---|
time | number | Yes | Specifies the time to format (defaults to the current time). |
UTC | boolean | Yes | Specifies if the UTC time needs to be used instead of local time (default is false ). |
Return value
Returns the formatted localized time string.