Skip to content

convertUnixToZoned

convertUnixToZoned(value: number, timeZone: string, unit?: UnixUnit): string
import { convertUnixToZoned } from "@northguild/gmt/unix/convert";

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

  • Converts to ZonedDateTime using the specified timezone.
  • Validates value, timezone, and epoch unit.
  • Returns “” for invalid input.
Parameter Type Description
value number epoch value (number)
timeZone string IANA timeZone identifier
unit `` optional unit, “seconds” or “milliseconds”

zoned ISO 8601 string or “” on invalid

convertUnixToZoned(1709164800000, "America/New_York") // "2024-02-29T00:00:00-05:00[America/New_York]"
convertUnixToZoned(1709164800, "UTC", "seconds") // "2024-02-29T00:00:00+00:00[UTC]"
convertUnixToZoned(-1, "UTC") // "1969-12-31T23:59:59.999Z[UTC]"

unix/convert/convertUnixToZoned.ts