convertUnixToZoned
Signature
Section titled “Signature”convertUnixToZoned(value: string | number, timeZone: string, options?: { epochUnit?: UnixUnit; }): stringConvert a unix epoch value to a zoned ISO 8601 datetime string.
- Converts to ZonedDateTime using the specified timezone (required; an unknown zone returns "").
valueis a safe integer or a string of optionally negative ASCII digits; anything else, or an instant outside the Temporal range, returns "".- An explicit
undefinedoptionsis the same as omitted; a non-objectoptions(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 callfromOffsetInstant({ instant, offset })for the local time with its full offset and no bracket.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | number | epoch value: a safe integer or a digit string |
timeZone | string | IANA name or a UTC offset to the minute (what isValidTimeZone accepts) |
Options
Section titled “Options”options
optional: how value is read
| Option | Type | Default | Description |
|---|---|---|---|
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 "". |
Returns
Section titled “Returns”zoned ISO 8601 string or "" on invalid
Related types
Section titled “Related types”Examples
Section titled “Examples”import { convertUnixToZoned } from "@northguild/gmt/unix/convert";
convertUnixToZoned(1709164800000, "America/New_York") // "2024-02-28T19:00:00-05:00[America/New_York]"