Skip to content

formatUtc

formatUtc(value: string, locale?: string, options?: FormatUtcOptions): string
import { 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.
  • timeZone controls the IANA zone used for rendering; defaults to "UTC".
  • includeTimeZoneName appends the localized timezone name when true.
Parameter Type Description
value string UTC ISO string to format
locale string optional: BCP 47 locale tag

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

the formatted date/time string, or “” on invalid input

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") // ""

utc/format/formatUtc.ts