Java TimeUnit Usage dateDiff(Date d1, Date d2)

Here you can find the source of dateDiff(Date d1, Date d2)

Description

Returns the number of days between d1 and d2.

License

Open Source License

Parameter

Parameter Description
d1 The lowest date on the range
d2 The highest date on the range

Return

The number of days between d1 and d2

Declaration

public static Long dateDiff(Date d1, Date d2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Date;
import java.util.concurrent.TimeUnit;

public class Main {
    /**/*from   w  w w.ja  va 2s. com*/
     * Returns the number of days between d1 and d2.
     * 
     * @param d1
     *            The lowest date on the range
     * @param d2
     *            The highest date on the range
     * @return The number of days between d1 and d2
     */
    public static Long dateDiff(Date d1, Date d2) {
        long diff = d2.getTime() - d1.getTime();
        return TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS);
    }
}

Related

  1. convertNanosecondTimespanToHumanReadableFormat(long aTimespan, boolean aShortFormat, boolean aLongFormat)
  2. convertNanoToSeconds(long nanoTime)
  3. createTimeString(int year, int month, int day, int hours, int minutes, int seconds, String timezoneID)
  4. createTimezoneString(String timezoneID)
  5. currentMillisFromNanotime()
  6. dateStart(final Calendar c)
  7. daysBetween(Calendar startDate, Calendar endDate)
  8. daysBetween(Date initDate, Date endDate)
  9. daysBetweenDates(long toDate, long fromDate)