convertUtcToUnix
Signature
Section titled “Signature”convertUtcToUnix(value: string, options?: { epochUnit?: UnixUnit; }): number | nullConvert a UTC Instant string to a unix epoch value in milliseconds or seconds.
- Uses Temporal.Instant.from to parse.
- Seconds floor toward −∞, so
"1969-12-31T23:59:59.5Z"is second-1(POSIXtime_t). optionsmust be an object or omitted: a non-object value (such as a bare"seconds"string) returns null.- Returns null for invalid input.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | UTC Instant string |
Options
Section titled “Options”options
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: "seconds" or "milliseconds", singular or plural. 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 { convertUtcToUnix } from "@northguild/gmt/utc/convert";
convertUtcToUnix("2024-02-29T00:00:00Z") // 1709164800000