List of utility methods to do Day Between
Date | stdNewDate(String tzDiff) std New Date Calendar cal = Calendar.getInstance(); Calendar cal1 = new GregorianCalendar(TimeZone.getTimeZone("GMT" + tzDiff)); try { Date dt = new Date(); cal1.setTimeInMillis(dt.getTime()); cal.set(Calendar.YEAR, cal1.get(Calendar.YEAR)); cal.set(Calendar.MONTH, cal1.get(Calendar.MONTH)); cal.set(Calendar.DAY_OF_MONTH, cal1.get(Calendar.DAY_OF_MONTH)); ... |
Date | substractDate(final Date date, final Integer different) Substract days. return addDate(date, -different);
|
Long | timeDifferenceInSeconds(Date startDate, Date endDate) time Difference In Seconds if (startDate == null || endDate == null) { return null; return (endDate.getTime() - startDate.getTime()) / (1000L); |
long | timeDifferenceWithCurrentTime(Date startTime) This Methods gives the result Milliseconds elapsed to Current Time Note : this method does not check for dates. Date currentTime = getCurrentDateTime();
Calendar startDateCal = Calendar.getInstance();
startDateCal.setTime(startTime);
Calendar newTime = Calendar.getInstance();
newTime.set(Calendar.HOUR, startDateCal.get(Calendar.HOUR));
newTime.set(Calendar.MINUTE, startDateCal.get(Calendar.MINUTE));
newTime.set(Calendar.MILLISECOND, startDateCal.get(Calendar.MILLISECOND));
return ((newTime.getTime()).getTime() - currentTime.getTime());
...
|
int | truncateDifferMonths(Date date) truncate Differ Months return truncateDifferMonths(date, new Date()); |
Integer | yearDifference(Date date1, Date date2) date2-date1 if either are null, it returns null. if (date1 == null || date2 == null) return (null); Calendar cal1 = new GregorianCalendar(); cal1.setTime(date1); Calendar cal2 = new GregorianCalendar(); cal2.setTime(date2); return (yearDifference(cal1, cal2)); |
int | yearTimeDiff(Date d1, Date d2) year Time Diff assertDateParamsRequired(d1, d2);
Calendar c1 = Calendar.getInstance();
c1.setTime(d1);
Calendar c2 = Calendar.getInstance();
c2.setTime(d2);
return c1.get(Calendar.YEAR) - c2.get(Calendar.YEAR);
|