get
Gets the value of a specific time unit from the date.
get()
Gets the value of a specific time unit from the date.
Signature
get<Unit extends TimeUnit>(unit: Unit): TimeUnitValue<Unit>Parameters
unit: Time unit to get:TimeUnit
Return Type
TimeUnitValue<Unit> - Component value
Example
playground.ts
Notes
- Return value for
monthis1based (1: January,12: December) - ISO weeks start on Monday, and the first week of the year is the one containing January 4th.
Type Definitions
/** Name of time unit from `year` to `millisecond` */
type TimeUnit = 'year' | 'month' | 'day' | 'week' | 'hour' | 'minute' | 'second' | 'millisecond';
/** Conditional value for `TimeUnit` */
type TimeUnitValue<Unit extends TimeUnit> =
Unit extends 'month' ? NumberRange<1, 12> // 1-12
: Unit extends 'week' ? NumberRange<1, 53> // 1-51
: Unit extends 'day' ? NumberRange<1, 31> // 1-31
: Unit extends 'hour' ? Enumerate<24> // 0-23
: Unit extends 'minute' | 'second' ? Enumerate<60> // 0-59
: Unit extends 'millisecond' ? Milliseconds // 0-999
: number;Last updated: Thu, May 21, 2026 09:14:30AM (UTC)
