Skip to content

getNowUnit

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

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.
  • Returns “” when unit is invalid or system timezone is unavailable.
Parameter Type Description
unit any unit to extract from current local time

string representation of the requested unit or “” on invalid

getNowUnit("year") // "2024"
getNowUnit("month") // "03"
getNowUnit("week") // "11"
getNowUnit("day") // "15"
getNowUnit("dayOfWeek") // "5"
getNowUnit("hour") // "14"
getNowUnit("minute") // "30"
getNowUnit("second") // "45"
getNowUnit("millisecond") // "000"
getNowUnit("microsecond") // "000"
getNowUnit("nanosecond") // "000"
getNowUnit("invalid") // ""

plain/get/getNowUnit.ts