Here you can find the source of getAfterDayNumber(Date endDate, Date startDate)
public static int getAfterDayNumber(Date endDate, Date startDate)
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; public class Main { public static int getAfterDayNumber(Date endDate, Date startDate) { Calendar cal = new GregorianCalendar(); cal.setTime(endDate);//from w w w .j a v a 2 s . co m cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE)); cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND)); Long date1 = cal.getTimeInMillis(); cal.setTime(startDate); cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE)); cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND)); Long date2 = cal.getTimeInMillis(); return (int) Math.floor((date1 - date2) / (24 * 3600 * 1000)); } }