getZonedNow
Signature
Section titled “Signature”getZonedNow(ianaTimezone: string, optionsArg?: { smallestUnit?: SmallestUnit<"minute" | "second" | "millisecond" | "microsecond" | "nanosecond"> | undefined; }): stringReturn the current zoned datetime for the specified IANA timeZone.
- Uses Temporal.Now.zonedDateTimeISO to get the current time.
- Validation is performed on the timezone.
smallestUnitis the only option read. Any other key onoptionsArgis ignored, so the string always carries the offset and the bracketed time zone, and smaller units are always truncated.- 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 |
|---|---|---|
ianaTimezone | string | IANA name or a UTC offset to the minute (what isValidTimeZone accepts) |
Options
Section titled “Options”optionsArg
optional setting for the precision of the output string
| Option | Type | Default | Description |
|---|---|---|---|
smallestUnit? | SmallestUnit<"minute" | "second" | "millisecond" | "microsecond" | "nanosecond"> | "millisecond" | The smallest unit written in the output string, from "minute" to "nanosecond", singular or plural. Anything smaller is truncated, as Temporal’s toString does with its "trunc" rounding mode. |
Returns
Section titled “Returns”zoned ISO 8601 datetime string or "" on invalid input
Examples
Section titled “Examples”import { getZonedNow } from "@northguild/gmt/zoned/get";
getZonedNow("America/New_York") // "2024-02-29T09:30:45.123-05:00[America/New_York]"