Skip to content

getUtcNowUnit

getUtcNowUnit(unit: UtcNowUnit): string

Return 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.
  • unit accepts 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").
ParameterTypeDescription
unitUtcNowUnitunit to extract from current utc instant

string representation of the requested unit or "" on invalid

Units extractable from the current UTC instant via getUtcNowUnit. Defined as DateTimeUnit | "dayOfWeek".

import type { UtcNowUnit } from "@northguild/gmt";
SmallestUnit<DateTimeUnit> | "dayOfWeek"
import { getUtcNowUnit } from "@northguild/gmt/utc/get";
getUtcNowUnit("year") // "2024"
output 

utc/get/getUtcNowUnit.ts