Here you can find the source of daysAfter(Date earlierDate, Date laterDate)
public static int daysAfter(Date earlierDate, Date laterDate)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { private static final Calendar CALENDAR = Calendar.getInstance(); private static final Calendar CALENDAR2 = Calendar.getInstance(); public static int daysAfter(Date earlierDate, Date laterDate) { final Calendar earlier = CALENDAR; final Calendar later = CALENDAR2; if (laterDate.before(earlierDate)) return 0; earlier.setTime(earlierDate);//from w w w . ja v a 2 s .com later.setTime(laterDate); int daysLater = later.get(Calendar.DAY_OF_YEAR) - earlier.get(Calendar.DAY_OF_YEAR); for (int year = earlier.get(Calendar.YEAR); year < later.get(Calendar.YEAR); year++) { earlier.set(Calendar.YEAR, year); daysLater += earlier.getActualMaximum(Calendar.DAY_OF_YEAR); } return daysLater; } }