Java Date Difference diff(Date endDate, Date startDate)

Here you can find the source of diff(Date endDate, Date startDate)

Description

diff

License

Apache License

Declaration

public static long diff(Date endDate, Date startDate) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;
import java.util.Date;

public class Main {

    public static long diff(Date endDate, Date startDate) {
        long endTime = getMillis(endDate);
        long startTime = getMillis(startDate);
        return endTime - startTime;
    }//from   w  w w .  j a  v a 2  s. c o  m

    public static boolean diff(Date endDate, Date startDate, int n) {
        long endTime = getMillis(endDate);
        long startTime = getMillis(startDate);
        return (endTime - startTime - n * 24 * 3600 * 1000L) > 0 ? true : false;
    }

    /**
     * get million
     * 
     * @param dt
     * @return
     */
    public static long getMillis(Date dt) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(dt);
        return cal.getTimeInMillis();
    }
}

Related

  1. dayDiffByStartOfDay(Date a, Date b)
  2. daysDiff(Date d1, Date d2)
  3. diff(Date d1, Date d2)
  4. diff(Date date1, Date date2)
  5. diff(Date date1, Date date2)
  6. diff(Date sDate, Date fDate)
  7. diff(Date subtrahend, Date minuend, long diffField)
  8. diff(int type, Date date1, Date date2)
  9. diff_in_date(Date d1, Date d2, String type)