Skip to content

getUtcNowUnit

getUtcNowUnit(unit: any): string
import { getUtcNowUnit } from "@northguild/gmt/utc/get";

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.
  • Returns “” on invalid unit or failure.
Parameter Type Description
unit any unit to extract from current utc instant

string representation of the requested unit or “” on invalid

getUtcNowUnit("year") // "2024"
getUtcNowUnit("month") // "02"
getUtcNowUnit("invalid") // ""

utc/get/getUtcNowUnit.ts