Get Time Difference
Calculates the difference between two dates in the specified time unit.
getTimeDiff
Function Signature
function getTimeDiff(date1: Maybe<DateArgs>, date2: Maybe<DateArgs>, unit?: TimeUnit): numberParameters
date1: The first date to compare. Can bestring,numberorDateobject.date2: The second date to compare. Can bestring,numberorDateobject.unit: The time unit to use for the difference. Defaults to'millisecond'.
Note
- For
undefineddate arguments it uses the current dates. - Throws
TypeErrorif the provided date is invalid (not parsable into a valid date byDateConstructor).
Returns
Returns the difference between date2 and date1 in the specified time unit.
Example Usage
playground.ts
Last updated: Sun, Jun 28, 2026 05:01:07AM (UTC)
