formatZonedDateTime
Signature
Section titled “Signature”formatZonedDateTime(value: string, locale?: string | string[], options?: DateTimeFormatOptions): stringFormat a zoned ISO 8601 datetime string using the Intl.DateTimeFormat implementation.
- Formats as Temporal’s ECMA-402 ZonedDateTime format (
ZonedDateTime#toLocaleString) does, through the runtime’sIntl.DateTimeFormatin the value’s own zone: the requested fields and widths are kept, and with no date or time field (eraalone included) the date, time and a short zone name are the defaults. - Accepts optional locale and Intl.DateTimeFormatOptions.
- Returns "" for invalid input, and for a
timeZoneoption, whereZonedDateTime#toLocaleStringthrows a TypeError. - Output is normalized: dash separators become ASCII ”-” (unspaced between digits, spaced otherwise), and no-break, narrow and thin spaces become U+0020.
- Compatibility: before 1.16.0 some locales and calendars lost a requested width (ja-JP with the japanese calendar and
month: "long"gave"R6/2") anderaalone dropped the time and zone name. Pass the fields the old text showed to keep it. To render in another zone, useformatUtcwith itstimeZoneoption. optionsnull returns"", as ECMA-402’s CoerceOptionsToObject rejects it (a string or number options value formats with the defaults, asIntl.DateTimeFormatdoes).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | zoned ISO 8601 datetime string |
locale | string | string[] | optional locale tag (e.g. “en-US”), or a preference list of tags (ECMA-402) |
Options
Section titled “Options”options
optional Intl.DateTimeFormatOptions
Type: DateTimeFormatOptions.
| Option | Type | Default | Description |
|---|---|---|---|
…Intl.DateTimeFormatOptions | — | — | Every field of DateTimeFormatOptions, as ECMA-402 defines it. |
Returns
Section titled “Returns”localized string or "" when invalid
Related types
Section titled “Related types”Examples
Section titled “Examples”import { formatZonedDateTime } from "@northguild/gmt/zoned/format";
formatZonedDateTime("2024-02-29T12:34:56.789+00:00[UTC]", "en-US", { dateStyle: "long", timeStyle: "long" }) // "February 29, 2024 at 12:34:56 PM UTC"