List of utility methods to do Date Difference
long | getDateDiff(String startTime, String endTime) get Date Diff long diff = 0; DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { Date d1 = df.parse(startTime); Date d2 = df.parse(endTime); diff = d2.getTime() - d1.getTime(); } catch (Exception e) { return diff; |
long | getDateDiffDay(String begindate, String enddate) get Date Diff Day long hourDiff = getDateDiffHour(begindate, enddate); Float dayDiff = (float) (hourDiff / 24); return dayDiff.intValue(); |
double | getDateDifference(String start, String end) get Date Difference double result; DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); String start_fixed = start.substring(0, 23); String end_fixed = end.substring(0, 23); try { Date startDate = format.parse(start_fixed); Date endDate = format.parse(end_fixed); result = endDate.getTime() - startDate.getTime(); ... |
int | getDateDifference(String startDateString, String endDateString) get Date Difference int returnVal = 0; if ((startDateString != null) && (endDateString != null)) { java.util.Date startDate = getDate(startDateString); java.util.Date endDate = getDate(endDateString); returnVal = getDateDifference(startDate, endDate); return returnVal; |
long | getDateDiffHour(String begindate, String enddate) get Date Diff Hour long minuteDiff = getDateDiffMinute(begindate, enddate); Float hourDiff = (float) (minuteDiff / 60); return hourDiff.intValue(); |
int | getDayDiff(Date firstDate, Date secondDate) Returns the difference of two dates in days (fristDay - secondDay). long fristDay = (int) (firstDate.getTime() / (86400. * 1000.)); long secondDay = (int) (secondDate.getTime() / (86400. * 1000.)); return (int) (fristDay - secondDay); |
long | getDiff(Date from, Date to) get Diff return from.getTime() - to.getTime();
|
String | getDiffDate(String srcDate, String format, int diff) get Diff Date DateFormat f = new SimpleDateFormat(format); try { Date source = f.parse(srcDate); Calendar c = Calendar.getInstance(); c.setTime(source); c.add(Calendar.DATE, diff); return f.format(c.getTime()); } catch (Exception e) { ... |
long | getDiffDays(Date from, Date to) get Diff Days return (to.getTime() - from.getTime()) / 86400000;
|
int | getDiffDays2(Date one, Date two) get Diff Days Calendar sysDate = new GregorianCalendar(); sysDate.setTime(one); Calendar failDate = new GregorianCalendar(); failDate.setTime(two); return (int) ((sysDate.getTimeInMillis() - failDate.getTimeInMillis()) / (24 * 60 * 60 * 1000)); |