Here you can find the source of diff(Date endDate, Date startDate)
public static long diff(Date endDate, Date startDate)
//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(); } }