Skip to content

getTimeZoneOffset

getTimeZoneOffset(timeZone: string, instant: string): string
import { getTimeZoneOffset } from "@northguild/gmt/zoned/get";

Return an IANA timeZone’s UTC offset at a given instant.

  • Unlike getZonedOffset, this doesn’t need an existing zoned value in hand — pass any timeZone identifier and an instant to look up, which is why (like getDstTransitions) it lives in get/ despite taking two arguments: neither is a date value being described, both are coordinates for a zone-level lookup.
  • Returns “” for an invalid timeZone or instant.
Parameter Type Description
timeZone string IANA timeZone identifier
instant string ISO 8601 instant string (e.g. “2024-07-15T12:00:00Z”)

offset string (e.g. “-04:00”), or “” on invalid input

getTimeZoneOffset("America/New_York", "2024-07-15T12:00:00Z") // "-04:00"
getTimeZoneOffset("America/New_York", "2024-01-15T12:00:00Z") // "-05:00"
getTimeZoneOffset("Asia/Kathmandu", "2024-01-15T12:00:00Z") // "+05:45"
getTimeZoneOffset("Invalid/Zone", "2024-07-15T12:00:00Z") // ""
getTimeZoneOffset("America/New_York", "not an instant") // ""

zoned/get/getTimeZoneOffset.ts