@Test public void testDiffDays() throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS"); { Date d1 = sdf.parse("2018-12-31 00:00:00:000"); Date d2 = sdf.parse("2018-12-31 23:59:59:999"); assertTrue(DateUtils.diffDays(d1, d2) == 0); } { Date d1 = sdf.parse("2018-12-30 00:00:00:000"); Date d2 = sdf.parse("2018-12-31 23:59:59:999"); assertTrue(DateUtils.diffDays(d1, d2) == -1); } { Date d1 = sdf.parse("2018-12-30 23:59:59:999"); Date d2 = sdf.parse("2018-12-31 00:00:00:000"); assertTrue(DateUtils.diffDays(d1, d2) == -1); } }
public static long diffDays(Date date1, Date date2) { final int offset = TimeZone.getDefault().getRawOffset(); return toDays(date1.getTime() + offset) - toDays(date2.getTime() + offset); }
DateUtils { public static long diffDays(Date date1, Date date2) { final int offset = TimeZone.getDefault().getRawOffset(); return toDays(date1.getTime() + offset) - toDays(date2.getTime() + offset); } }
DateUtils { public static long diffDays(Date date1, Date date2) { final int offset = TimeZone.getDefault().getRawOffset(); return toDays(date1.getTime() + offset) - toDays(date2.getTime() + offset); }  }
DateUtils { public static long diffDays(Date date1, Date date2) { final int offset = TimeZone.getDefault().getRawOffset(); return toDays(date1.getTime() + offset) - toDays(date2.getTime() + offset); }  static boolean isSameDay(final Date date1, final Date date2); static boolean isSameDay(final Calendar cal1, final Calendar cal2); static boolean isSameWeek(final Date date1, final Date date2); static boolean isSameWeek(Calendar cal1, Calendar cal2); static boolean isSameMonth(final Date date1, final Date date2); static boolean isSameMonth(Calendar cal1, Calendar cal2); static Date addYears(final Date date, final int amount); static Date addMonths(final Date date, final int amount); static Date addWeeks(final Date date, final int amount); static Date addDays(final Date date, final int amount); static Date addHours(final Date date, final int amount); static Date addMinutes(final Date date, final int amount); static Date addSeconds(final Date date, final int amount); static Date addMilliseconds(final Date date, final int amount); static long toSeconds(Date date); static long toSeconds(long milliseconds); static long toSecondsByStartOfDay(LocalDate localDate); static long toDays(Date date); static long toDays(long milliseconds); static long diffSeconds(Date date1, Date date2); static long diffDays(Date date1, Date date2); static String formatTime(long seconds); }
DateUtils { public static long diffDays(Date date1, Date date2) { final int offset = TimeZone.getDefault().getRawOffset(); return toDays(date1.getTime() + offset) - toDays(date2.getTime() + offset); }  static boolean isSameDay(final Date date1, final Date date2); static boolean isSameDay(final Calendar cal1, final Calendar cal2); static boolean isSameWeek(final Date date1, final Date date2); static boolean isSameWeek(Calendar cal1, Calendar cal2); static boolean isSameMonth(final Date date1, final Date date2); static boolean isSameMonth(Calendar cal1, Calendar cal2); static Date addYears(final Date date, final int amount); static Date addMonths(final Date date, final int amount); static Date addWeeks(final Date date, final int amount); static Date addDays(final Date date, final int amount); static Date addHours(final Date date, final int amount); static Date addMinutes(final Date date, final int amount); static Date addSeconds(final Date date, final int amount); static Date addMilliseconds(final Date date, final int amount); static long toSeconds(Date date); static long toSeconds(long milliseconds); static long toSecondsByStartOfDay(LocalDate localDate); static long toDays(Date date); static long toDays(long milliseconds); static long diffSeconds(Date date1, Date date2); static long diffDays(Date date1, Date date2); static String formatTime(long seconds); static final int MILLISECOND_PER_SECOND; static final int SECOND_PER_MINUTE; static final int MINUTE_PER_HOUR; static final int HOUR_PER_DAY; }