Here you can find the source of getDateDifferenceinDays(Date date1, Date date2)
public static Integer getDateDifferenceinDays(Date date1, Date date2)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static Integer getDateDifferenceinDays(Date date1, Date date2) { if (date1 == null || date2 == null) return null; long diff = 0L; diff = Math.abs(date1.getTime() - date2.getTime()); long oneDayseconds = getSecondsForDay(); Integer result = (int) (diff / oneDayseconds); return result; }/*www . j a va 2 s.c om*/ public static long getSecondsForDay() { Date d1 = getDateFor(2009, 10, 10, 00, 00, 00); Date d2 = getDateFor(2009, 10, 10, 23, 59, 59); long seconds = d2.getTime() - d1.getTime(); return seconds; } /** * This method returns the date for the passed year month day hours minutes seconds * * @param year * @param month * @param day * @param hours * @param minutes * @param seconds * @return */ public static Date getDateFor(int year, int month, int day, int hours, int minutes, int seconds) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DAY_OF_MONTH, day); cal.set(Calendar.HOUR_OF_DAY, hours); cal.set(Calendar.MINUTE, minutes); cal.set(Calendar.SECOND, seconds); return cal.getTime(); } }