List of utility methods to do Date Difference
long | dateDiff(Date beginDate, Date endDate) date Diff long beginDateseconds = beginDate.getTime(); long endDateseconds = endDate.getTime(); long diff = endDateseconds - beginDateseconds; long diffDays = diff / (24 * 60 * 60 * 1000); return diffDays; |
long | dateDiff(Date d1, Date d2, int field) date Diff long j = 1; switch (field) { case Calendar.YEAR: return dateDiffYear(d1, d2); case Calendar.MONTH: return dateDiffMonth(d1, d2); case Calendar.DATE: j = 1000 * 60 * 60 * 24; ... |
String | dateDiff(Date date1, Date date2) date Diff long milliseconds1 = date1.getTime(); long milliseconds2 = date2.getTime(); long diff = milliseconds2 - milliseconds1; long diffSeconds = diff / 1000; long diffMinutes = diff / (60 * 1000); long diffHours = diff / (60 * 60 * 1000); long diffDays = diff / (24 * 60 * 60 * 1000); diffSeconds = diffSeconds - (diffMinutes * 60); ... |
int | dateDiff(Date date1, Date date2) Returns the difference in days between date1 and date2 Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.setTime(date1); cal2.setTime(date2); int diff = 0; while (cal1.before(cal2)) { cal1.add(Calendar.DATE, 1); diff++; ... |
int | dateDiff(Date date1, Date date2) date Diff int count = 0; int diff = 0; Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.setTime(date1); cal2.setTime(date2); while (cal1.get(Calendar.YEAR) != cal2.get(Calendar.YEAR)) { count = 365 * (cal2.get(Calendar.YEAR) - cal1.get(Calendar.YEAR)); ... |
long | dateDiff(Date fromDate, Date toDate) date Diff return dateDiff(getDateTime(DATE_PATTERN, fromDate), getDateTime(DATE_PATTERN, toDate));
|
long | DateDiff(Date startDate, Date endDate) Date Diff long totalDate = 0; Calendar calendar = Calendar.getInstance(); calendar.setTime(startDate); long timestart = calendar.getTimeInMillis(); calendar.setTime(endDate); long timeend = calendar.getTimeInMillis(); totalDate = (timeend - timestart) / (1000 * 60 * 60 * 24); return totalDate; ... |
long | dateDiff(final Date date1, final Date date2) Calculate difference in milliseconds from 2 dates. long result = date1.getTime() - date2.getTime(); return result; |
int | dateDiff(int category, Date date1, Date date2) date Diff Calendar c1 = Calendar.getInstance(); c1.setTime(date1); Calendar c2 = Calendar.getInstance(); c2.setTime(date2); if (YEAR == category) { return Math.abs(c2.get(Calendar.YEAR) - c1.get(Calendar.YEAR)); } else if (MONTH == category) { return Math.abs((((c2.get(Calendar.YEAR) - c1.get(Calendar.YEAR)) * 12) + c2.get(Calendar.MONTH)) ... |
int | dateDiff(int interval, Date begin, Date end) date Diff long beginTime = begin.getTime() / 1000L; long endTime = end.getTime() / 1000L; long tmp = 0L; if (endTime == beginTime) { return 0; if (endTime < beginTime) { tmp = beginTime; ... |