formatUtc
Signature
Section titled “Signature”formatUtc(value: string, locale?: string, options?: FormatUtcOptions): stringimport { formatUtc } from "@northguild/gmt/utc/format";Format a UTC ISO string as a localized date/time string.
- Returns
""if the input is not a valid UTC string. timeZonecontrols the IANA zone used for rendering; defaults to"UTC".includeTimeZoneNameappends the localized timezone name when true.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string |
UTC ISO string to format |
locale |
string |
optional: BCP 47 locale tag |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
timeZone? |
string |
— |
includeTimeZoneName? |
boolean |
— |
localeMatcher? |
"best fit" | "lookup" |
— |
weekday? |
"long" | "short" | "narrow" |
— |
era? |
"long" | "short" | "narrow" |
— |
year? |
"numeric" | "2-digit" |
— |
month? |
"long" | "short" | "narrow" | "numeric" | "2-digit" |
— |
day? |
"numeric" | "2-digit" |
— |
hour? |
"numeric" | "2-digit" |
— |
minute? |
"numeric" | "2-digit" |
— |
second? |
"numeric" | "2-digit" |
— |
timeZoneName? |
"long" | "short" | "shortOffset" | "longOffset" | "shortGeneric" | "longGeneric" |
— |
formatMatcher? |
"best fit" | "basic" |
— |
hour12? |
boolean |
— |
calendar? |
string |
— |
dayPeriod? |
"long" | "short" | "narrow" |
— |
numberingSystem? |
string |
— |
dateStyle? |
"long" | "short" | "medium" | "full" |
— |
timeStyle? |
"long" | "short" | "medium" | "full" |
— |
hourCycle? |
"h11" | "h12" | "h23" | "h24" |
— |
fractionalSecondDigits? |
1 | 2 | 3 |
— |
Returns
Section titled “Returns”the formatted date/time string, or “” on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”formatUtc("2026-03-16T18:30:00Z") // "3/16/2026, 6:30:00 PM"formatUtc("2026-03-16T18:30:00Z", "en-US", { timeZone: "America/New_York" }) // "3/16/2026, 2:30:00 PM"formatUtc("2026-03-16T18:30:00Z", "en-US", { timeZone: "America/New_York", includeTimeZoneName: true }) // "3/16/2026, 2:30:00 PM EDT"formatUtc("not-a-date") // ""