Skip to content

convertZonedToUnix

convertZonedToUnix(value: string, options?: { epochUnit?: UnixUnit; }): number | null

Convert an ISO 8601 zoned datetime string to a unix epoch value in milliseconds (default) or seconds.

  • Uses Temporal.ZonedDateTime.toInstant to convert.
  • Seconds floor toward −∞, as POSIX time_t counts whole elapsed seconds.
  • A non-object options (such as a bare "seconds" string) returns null.
  • Returns null for invalid input.
ParameterTypeDescription
valuestringzoned ISO 8601 datetime string

options

optional setting for the unit of the returned epoch value

OptionTypeDefaultDescription
epochUnit?"seconds" | "milliseconds" | "second" | "millisecond" (UnixUnit)"milliseconds"The unit the epoch value is returned in: "milliseconds" or "seconds", each also accepted in its singular form. An explicit undefined is the same as omitted; any other value returns null.

epoch number or null on invalid

import { convertZonedToUnix } from "@northguild/gmt/zoned/convert";
convertZonedToUnix("2024-02-29T12:34:56.789+00:00[UTC]") // 1709210096789
output 

zoned/convert/convertZonedToUnix.ts