Here you can find the source of diffDay(Date start, Date end)
public static long diffDay(Date start, Date end)
//package com.java2s; //License from project: Apache License import java.util.Calendar; import java.util.Date; public class Main { public static long diffDay(Date start, Date end) { return offset(start, end, Calendar.DAY_OF_YEAR); }/*from w ww. ja va2s . co m*/ private static long offset(Date start, Date end, int offsetCalendarField) { boolean bool = start.before(end); long rtn = 0; Calendar s = Calendar.getInstance(); Calendar e = Calendar.getInstance(); s.setTime(bool ? start : end); e.setTime(bool ? end : start); rtn -= s.get(offsetCalendarField); rtn += e.get(offsetCalendarField); while (s.get(Calendar.YEAR) < e.get(Calendar.YEAR)) { rtn += s.getActualMaximum(offsetCalendarField); s.add(Calendar.YEAR, 1); } return bool ? rtn : -rtn; } public static Date add(Date date, int n, int calendarField) { Calendar c = Calendar.getInstance(); c.setTime(date); c.add(calendarField, n); return c.getTime(); } }