ChronosChronos

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): number

Parameters

  • date1: The first date to compare. Can be string, number or Date object.
  • date2: The second date to compare. Can be string, number or Date object.
  • unit: The time unit to use for the difference. Defaults to 'millisecond'.

Note

  • For undefined date arguments it uses the current dates.
  • Throws TypeError if the provided date is invalid (not parsable into a valid date by DateConstructor).

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)

On this page