(版本1)
publicstaticint getIntervalDays(Date fDate, Date oDate) { if (null == fDate || null == oDate) { return -1; } long intervalMilli = oDate.getTime() - fDate.getTime(); return (int) (intervalMilli / (24 * 60 * 60 * 1000)); }
(版本2)
publicstaticint daysOfTwo(Date fDate, Date oDate) { Calendar aCalendar = Calendar.getInstance(); aCalendar.setTime(fDate); int day1 = aCalendar.get(Calendar.DAY_OF_YEAR); aCalendar.setTime(oDate); int day2 = aCalendar.get(Calendar.DAY_OF_YEAR); return day2 - day1; }