Here you can find the source of daysBetween2Dates(Date startDate, Date endDate)
public static long daysBetween2Dates(Date startDate, Date endDate)
//package com.java2s; // distribute, sublicense, and/or sell copies of the Software, and to import java.util.Calendar; import java.util.Date; public class Main { public static long daysBetween2Dates(Date startDate, Date endDate) { Calendar startDateCal = Calendar.getInstance(); startDateCal.setTime(startDate); startDateCal.set(Calendar.HOUR, 0); startDateCal.set(Calendar.MINUTE, 0); startDateCal.set(Calendar.SECOND, 0); startDateCal.set(Calendar.MILLISECOND, 0); Calendar endDateCal = Calendar.getInstance(); endDateCal.setTime(endDate);//from w ww. j av a 2s.c om endDateCal.set(Calendar.HOUR, 0); endDateCal.set(Calendar.MINUTE, 0); endDateCal.set(Calendar.SECOND, 0); endDateCal.set(Calendar.MILLISECOND, 0); return (startDateCal.getTime().getTime() - endDateCal.getTime().getTime()) / (24 * 3600 * 1000); } }