Skip to content

convertUnixToZoned

convertUnixToZoned(value: string | number, timeZone: string, options?: { epochUnit?: UnixUnit; }): string

Convert a unix epoch value to a zoned ISO 8601 datetime string.

  • Converts to ZonedDateTime using the specified timezone (required; an unknown zone returns "").
  • value is a safe integer or a string of optionally negative ASCII digits; anything else, or an instant outside the Temporal range, returns "".
  • An explicit undefined options is the same as omitted; a non-object options (such as a bare "seconds" string) returns "".
  • An offset with seconds (-00:44:30) returns "". A written zone cannot carry seconds (RFC 9557 §4.1), so the result could not name it. Pass the IANA name, or call fromOffsetInstant({ instant, offset }) for the local time with its full offset and no bracket.
ParameterTypeDescription
valuestring | numberepoch value: a safe integer or a digit string
timeZonestringIANA name or a UTC offset to the minute (what isValidTimeZone accepts)

options

optional: how value is read

OptionTypeDefaultDescription
epochUnit?"seconds" | "milliseconds" | "second" | "millisecond" (UnixUnit)"milliseconds"The unit the epoch values are counted in: "seconds" or "milliseconds", singular or plural. Any other value returns "".

zoned ISO 8601 string or "" on invalid

import { convertUnixToZoned } from "@northguild/gmt/unix/convert";
convertUnixToZoned(1709164800000, "America/New_York") // "2024-02-28T19:00:00-05:00[America/New_York]"
output 

unix/convert/convertUnixToZoned.ts