getDiff

Commons
stable

Computes the difference between two dates in the requested unit (years, quarters, months, weeks, days, hours, minutes, seconds). Falls back to milliseconds when no unit is supplied.

API

Signature

Signature TypeScript complète, extraite du fichier util.

typescript

API

Paramètres

Paramètres d'entrée acceptés par cet util.

date
requis
Date
The reference (start) date.
comparing
requis
Date | string
The date to compare against. Strings are parsed via new Date().
unit
string
One of "years" | "quarters" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds". Omit for milliseconds.

API

Valeur de retour

La valeur retournée par cet util.

The signed integer (or millisecond float) difference. Positive when date is after comparing.

Usage

Exemples

Extraits de code prêts à coller.

Diff in days and months

typescript