Skip to content

formatRelativeDateTime

Playground

call
result 
formatRelativeDateTime(value: string, locale?: string, options?: FormatRelativeDateTimeOptions): string
import { formatRelativeDateTime } from "@northguild/gmt/plain/format";

Format the relative time between a plain date-time and a reference date-time.

  • Auto-picks the display unit (second through year) based on the distance, unless largestUnit forces one.
  • roundingMethod controls how the distance rounds to the display unit.
Parameter Type Description
value string ISO date-time string to format
locale string optional: BCP 47 locale tag

options

Option Type Default
style? "long" | "short" | "narrow"
numeric? "always" | "auto"
largestUnit? RelativeUnit
roundingMethod? RelativeRoundingMethod
reference? string

the formatted relative-time string, or “” on invalid input

formatRelativeDateTime("2026-03-17T09:00:00", "en-GB", { style: "long" }) // "in 3 hours"
formatRelativeDateTime(value, "en-US", { roundingMethod: "floor" }) // rounds toward the earlier boundary
formatRelativeDateTime("not-a-date") // ""

plain/format/formatRelativeDateTime.ts