Here you can find the source of daysBetween(Date initDate, Date endDate)
public static long daysBetween(Date initDate, Date endDate)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; import java.util.concurrent.TimeUnit; public class Main { public static long daysBetween(Date initDate, Date endDate) { return daysBetween(initDate, endDate, true); }// w w w.j a v a 2 s .c om public static long daysBetween(Date initDate, Date endDate, Boolean includeEndDate) { return getDifference(toDateCalendar(initDate), toDateCalendar(endDate), TimeUnit.DAYS) + (includeEndDate ? 1 : 0); } public static long getDifference(Calendar initDate, Calendar endDate, TimeUnit units) { return units.convert(endDate.getTimeInMillis() - initDate.getTimeInMillis(), TimeUnit.MILLISECONDS); } public static Calendar toDateCalendar(Date date) { if (date != null) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(date.getTime()); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); return calendar; } return null; } }