Skip to content

getNowUnit

getNowUnit(unit: NowUnit): string

Return the requested current unit value using the system timeZone.

  • Valid units: “year”, “month”, “week”, “day”, “dayOfWeek”, “hour”, “minute”, “second”, “millisecond”, “microsecond”, “nanosecond”.
  • Uses Temporal.Now.zonedDateTimeISO to get current time in system timezone.
  • unit accepts the singular or plural name of a Temporal unit ("hour" or "hours"), as Temporal does; "dayOfWeek" has no plural.
  • Returns "" when unit is invalid or system timezone is unavailable.
  • 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
unitNowUnitunit to extract from current local time

string representation of the requested unit or "" on invalid

Units extractable from the current system local time via getNowUnit. Defined as DateTimeUnit | "dayOfWeek".

import type { NowUnit } from "@northguild/gmt";
SmallestUnit<DateTimeUnit> | "dayOfWeek"
import { getNowUnit } from "@northguild/gmt/plain/get";
getNowUnit("year") // "2024"
output 

plain/get/getNowUnit.ts