ChronosChronos

set

Returns a new Chronos instance with the specified unit set to the given value.

set()

Returns a new Chronos instance with the specified unit set to the given value.

Signature

set<Unit extends TimeUnit>(unit: Unit, value: TimeUnitValue<Unit>): Chronos

Parameters

Return Type

Chronos - New instance with updated value

Example

playground.ts

N.B.

Unit month is 1 based (1: January, 12: December)

See Also

with static method for more options

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)

On this page