Here you can find the source of daysOfTwoDate(Date beginDate, Date endDate)
public static int daysOfTwoDate(Date beginDate, Date endDate)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static int daysOfTwoDate(Date beginDate, Date endDate) { Calendar beginCalendar = Calendar.getInstance(); Calendar endCalendar = Calendar.getInstance(); beginCalendar.setTime(beginDate); endCalendar.setTime(endDate);/*from w w w. j a v a 2 s . c o m*/ return getDaysBetween(beginCalendar, endCalendar); } public static int getDaysBetween(Calendar d1, Calendar d2) { int days = 0; int years = d1.get(Calendar.YEAR) - d2.get(Calendar.YEAR); if (years == 0) { days = d2.get(Calendar.DAY_OF_YEAR) - d1.get(Calendar.DAY_OF_YEAR); return days; } else if (years > 0) { for (int i = 0; i < years; i++) { d2.add(Calendar.YEAR, 1); days += -d2.getActualMaximum(Calendar.DAY_OF_YEAR); if (d1.get(Calendar.YEAR) == d2.get(Calendar.YEAR)) { days += d2.get(Calendar.DAY_OF_YEAR) - d1.get(Calendar.DAY_OF_YEAR); return days; } } } else { for (int i = 0; i < -years; i++) { d1.add(Calendar.YEAR, 1); days += d1.getActualMaximum(Calendar.DAY_OF_YEAR); if (d1.get(Calendar.YEAR) == d2.get(Calendar.YEAR)) { days += d2.get(Calendar.DAY_OF_YEAR) - d1.get(Calendar.DAY_OF_YEAR); return days; } } } return days; } }