Here you can find the source of getDaysBetween(Date startDate, Date endDate)
public static int getDaysBetween(Date startDate, Date endDate)
//package com.java2s; import java.util.Calendar; import java.util.Date; public class Main { public static int getDaysBetween(Date startDate, Date endDate) { int days = 0; Calendar startCalendar = Calendar.getInstance(); startCalendar.setTime(startDate); startCalendar.set(Calendar.HOUR_OF_DAY, 0); startCalendar.set(Calendar.MINUTE, 0); startCalendar.set(Calendar.SECOND, 0); Calendar endCalendar = Calendar.getInstance(); endCalendar.setTime(endDate);// ww w. j a v a 2s.c o m endCalendar.set(Calendar.HOUR_OF_DAY, 0); endCalendar.set(Calendar.MINUTE, 0); endCalendar.set(Calendar.SECOND, 0); if (startCalendar.after(endCalendar)) { while (startCalendar.after(endCalendar)) { days--; startCalendar.roll(Calendar.DAY_OF_YEAR, 1); } return days; } else { while (startCalendar.before(endCalendar)) { days++; startCalendar.add(Calendar.DAY_OF_YEAR, 1); } return days; } } }