formatTime
Signature
Section titled “Signature”formatTime(value: string, locale?: string | string[], options?: DateTimeFormatOptions): stringReturn a localized string for a PlainTime ISO input using Intl options.
- Formats as Temporal’s ECMA-402 PlainTime format (
PlainTime#toLocaleString) does, through the runtime’sIntl.DateTimeFormat.eraandtimeZoneNameare ignored, so alone they get the hour, minute and second defaults. - Accepts optional BCP 47 locale and Intl.DateTimeFormatOptions.
- Returns "" for invalid input, for a
dateStyle(with or withouttimeStyle) and for only date fields, wherePlainTime#toLocaleStringthrows a TypeError. - Compatibility: before 1.16.0
eraortimeZoneNamealone returned"",erabeside a time field added the era name, and adateStylebesidetimeStylewas ignored. Pass onlytimeStyleto keep the styled text. optionsnull returns"", as ECMA-402’s CoerceOptionsToObject rejects it. Any other non-object — a string, a number, a boolean — formats with the defaults, asIntl.DateTimeFormatdoes: CoerceOptionsToObject calls ToObject on it and the wrapper carries no recognised option. Onlynullandundefinedare special-cased.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | ISO PlainTime string |
locale | string | string[] | optional BCP 47 locale identifier, 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 time string or "" on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { formatTime } from "@northguild/gmt/plain/format";
formatTime("14:30:00", "en-US", { timeStyle: "short" }) // "2:30 PM"