• Calculate the difference in duration between 2 date objects, expressed in the specified time unit.

    Example

    getTimeDiff(new Date(2020, 3, 2, 10, 30), new Date(2020, 3, 2, 8, 0), TimeUnit.HOURS)) // 2.5
    getTimeDiff(new Date(2020, 3, 10), new Date(2020, 3, 3), TimeUnit.DAYS)) // 7
    getTimeDiff(new Date(2020, 3, 10), new Date(2020, 1, 10), TimeUnit.MONTHS)) // 2

    Returns

    Time difference expressed in the specified time unit

    Parameters

    • date1: Date

      JavaScript date object

    • date2: Date

      JavaScript date object (this will be subtracted from date1)

    • unit: TimeUnit

      Time unit to return

    Returns number

Generated using TypeDoc