List of utility methods to do Date Interval Get
int | DaysBetween(Date beginDate, Date endDate) Days Between Calendar cal = Calendar.getInstance(); cal.setTime(beginDate); long beginTime = cal.getTimeInMillis(); cal.setTime(endDate); long EndTime = cal.getTimeInMillis(); long between_days = (EndTime - beginTime) / (1000 * 3600 * 24); return Integer.parseInt(String.valueOf(between_days)); |
long | calculateDiffInDays(Date date1, Date date2) Calculates the difference between the given Date in days. if (StringUtils.isNull(date1)) { throw new NullPointerException("date1 cannot be null"); if (StringUtils.isNull(date2)) { throw new NullPointerException("date2 cannot be null"); long differenceInDays = (calculateDiffInHours(date1, date2)) / 24; return differenceInDays; ... |
long | calculateDiffInHours(Date date1, Date date2) Calculates the difference between the given Date in hours. if (StringUtils.isNull(date1)) { throw new NullPointerException("date1 cannot be null"); if (StringUtils.isNull(date2)) { throw new NullPointerException("date2 cannot be null"); long differenceInHours = (calculateDiffInMilliSeconds(date1, date2)) / MILLIS_PER_HOUR; ... |
long | calculateDiffInMilliSeconds(Date date1, Date date2) Calculates the difference between the given Date in milliseconds. if (StringUtils.isNull(date1)) { throw new NullPointerException("date1 cannot be null"); if (StringUtils.isNull(date2)) { throw new NullPointerException("date2 cannot be null"); long milliseconds1 = date1.getTime(); long milliseconds2 = date2.getTime(); ... |
long | calculateDiffInMinutes(Date date1, Date date2) Calculates the difference between the given Date in minutes. if (StringUtils.isNull(date1)) { throw new NullPointerException("date1 cannot be null"); if (StringUtils.isNull(date2)) { throw new NullPointerException("date2 cannot be null"); long differenceInMinutes = (calculateDiffInMilliSeconds(date1, date2)) / MILLIS_PER_MINUTE; ... |
String | dateDiff(String startTime, String endTime) date Diff String result = ""; SimpleDateFormat sd = new SimpleDateFormat(YMD_DASH_WITH_TIME); long nd = 1000 * 24 * 60 * 60; long nh = 1000 * 60 * 60; long nm = 1000 * 60; long ns = 1000; long diff; long day = 0; ... |
Long | dateDiff(String startTime, String endTime, String format, String str) date Diff SimpleDateFormat sd = new SimpleDateFormat(format); long nd = 1000 * 24 * 60 * 60; long nh = 1000 * 60 * 60; long nm = 1000 * 60; long ns = 1000; long diff; long day = 0; long hour = 0; ... |
int | dayDiff(Date date1, Date date2) day Diff long diff = date1.getTime() - date2.getTime(); return (int) (diff / DAY); |
Date | dayOffset(Date date, int offset) day Offset return offsetDate(date, Calendar.DATE, offset);
|
long | daysBetweenDate(Date date1, Date date2) days Between Date long d = date1.getTime() - date2.getTime(); return d / 86400000; |