Here you can find the source of daysBetweenDates(Date beginDate, Date endDate)
public static int daysBetweenDates(Date beginDate, Date endDate)
//package com.java2s; import java.util.*; public class Main { public static int daysBetweenDates(Date beginDate, Date endDate) { int days = 0; Calendar calo = Calendar.getInstance(); Calendar caln = Calendar.getInstance(); calo.setTime(beginDate);/* w w w . j ava2 s . c om*/ caln.setTime(endDate); int oday = calo.get(6); int nyear = caln.get(1); for (int oyear = calo.get(1); nyear > oyear;) { calo.set(2, 11); calo.set(5, 31); days += calo.get(6); oyear++; calo.set(1, oyear); } int nday = caln.get(6); days = (days + nday) - oday; return days; } }