Skip to content

getUnixNowUnit

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

Return the requested unit value from the current Unix timestamp in UTC.

  • Valid units: “year”, “month”, “week”, “day”, “dayOfWeek”, “hour”, “minute”, “second”, “millisecond”, “microsecond”, “nanosecond”.
  • Uses Temporal.Now.instant() converted to UTC zoned date time.
  • Returns “” on invalid unit or failure.
Parameter Type Description
unit any unit to extract from current unix timestamp

string representation of the requested unit or “” on invalid

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

unix/get/getUnixNowUnit.ts