addTime
addTime(
date: Date,
amount: number,
unit: 'years' | 'months' | 'weeks' | 'days' | 'hours' | 'minutes' | 'seconds',
): DateSource: date.ts:230
Adds a duration to a date
Parameters
date(Date) — Base dateamount(number) — Amount to addunit("years" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds") — Unit of time
Returns
Date— New date with added duration
Example
CODE
const now = new Date()
addTime(now, 1, 'day') // Tomorrow
addTime(now, -1, 'week') // Last week
addTime(now, 2, 'hours') // 2 hours from now