convertZonedToUnix
Signature
Section titled “Signature”convertZonedToUnix(value: string, options?: { epochUnit?: UnixUnit; }): number | nullConvert 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_tcounts whole elapsed seconds. - A non-object
options(such as a bare"seconds"string) returns null. - Returns null for invalid input.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | zoned ISO 8601 datetime string |
Options
Section titled “Options”options
optional setting for the unit of the returned epoch value
| Option | Type | Default | Description |
|---|---|---|---|
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. |
Returns
Section titled “Returns”epoch number or null on invalid
Related types
Section titled “Related types”Examples
Section titled “Examples”import { convertZonedToUnix } from "@northguild/gmt/zoned/convert";
convertZonedToUnix("2024-02-29T12:34:56.789+00:00[UTC]") // 1709210096789