getUtcNowUnit
Signature
Section titled “Signature”getUtcNowUnit(unit: UtcNowUnit): stringReturn the requested unit value from the current UTC instant.
- Valid units: “year”, “month”, “week”, “day”, “dayOfWeek”, “hour”, “minute”, “second”, “millisecond”, “microsecond”, “nanosecond”.
- Uses Temporal.Now.instant() converted to UTC.
unitaccepts the singular or plural name of a Temporal unit ("hour"or"hours"), as Temporal does;"dayOfWeek"has no plural.- Returns "" on invalid unit or failure.
- The
"year"unit is written as Temporal writes a year: four digits ("2024","0005"), or a sign and six digits outside 0000–9999 ("+010000","-000005").
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
unit | UtcNowUnit | unit to extract from current utc instant |
Returns
Section titled “Returns”string representation of the requested unit or "" on invalid
UtcNowUnit
Section titled “UtcNowUnit”Units extractable from the current UTC instant via getUtcNowUnit. Defined as DateTimeUnit | "dayOfWeek".
import type { UtcNowUnit } from "@northguild/gmt";SmallestUnit<DateTimeUnit> | "dayOfWeek"Examples
Section titled “Examples”import { getUtcNowUnit } from "@northguild/gmt/utc/get";
getUtcNowUnit("year") // "2024"