List of utility methods to do Day Between
Date | getDateDiffYear(Date date, int diff, String... format) get Date Diff Year Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.YEAR, diff);
return calendar.getTime();
|
Date | getDateWithDiff(Date date, int amount) get Date With Diff return getDateWithDiff(date, amount, Calendar.DATE);
|
int | getDaysBetween(Date date1, Date date2) gets days between any two dates (integer form) regardless of order GregorianCalendar d1 = new GregorianCalendar(); d1.setTime(date1); GregorianCalendar d2 = new GregorianCalendar(); d2.setTime(date2); if (d1.after(d2)) { GregorianCalendar swap = d1; d1 = d2; d2 = swap; ... |
int | getDaysBetween(Date start, Date end) get Days Between if (start == null) return 0; boolean negative = false; if (end.before(start)) { negative = true; Date temp = start; start = end; end = temp; ... |
int | getDaysBetween(Date start, Date end) Calculates the number of days between start and end .
if (start == null || end == null) { return -1; Calendar startDate = convertDate(start); truncCalendar(startDate); Calendar endDate = convertDate(end); truncCalendar(endDate); long endL = endDate.getTimeInMillis() + endDate.getTimeZone().getOffset(endDate.getTimeInMillis()); ... |
int | getDaysBetween(Date startDate, Date endDate) get Days Between int days = 0;
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(startDate);
startCalendar.set(Calendar.HOUR_OF_DAY, 0);
startCalendar.set(Calendar.MINUTE, 0);
startCalendar.set(Calendar.SECOND, 0);
Calendar endCalendar = Calendar.getInstance();
endCalendar.setTime(endDate);
...
|
int | getDaysBetween(Date startDate, Date endDate) Returns the number of calendar days between two dates. int daysBetween = -1; if (startDate.after(endDate)) return daysBetween; Calendar c = Calendar.getInstance(); if (startDate.after(endDate)) return daysBetween; c.setTime(startDate); int startYear = c.get(Calendar.YEAR); ... |
int | getDaysBetweenDate(Date begin, Date end) get Days Between Date int bDay = getDateField(begin, Calendar.DAY_OF_YEAR); int eDay = getDateField(end, Calendar.DAY_OF_YEAR); return eDay - bDay; |
int | getDaysDiff(Date startDate, Date endDate) Gets the difference in days between the given dates. Calendar fromCalendar = Calendar.getInstance(); fromCalendar.setTime(startDate); fromCalendar.set(Calendar.HOUR_OF_DAY, 0); fromCalendar.set(Calendar.MINUTE, 0); fromCalendar.set(Calendar.SECOND, 0); fromCalendar.set(Calendar.MILLISECOND, 0); Calendar toCalendar = Calendar.getInstance(); toCalendar.setTime(endDate); ... |
long | getDaysDifference(final Date begin, final Date end) Calculate diff in days between dates. long milliseconds; long days; final Calendar calendarBegin = new GregorianCalendar(); final Calendar calendarEnd = new GregorianCalendar(); calendarBegin.setTime(begin); calendarBegin.set(Calendar.HOUR_OF_DAY, 0); calendarBegin.set(Calendar.MINUTE, 0); calendarBegin.set(Calendar.SECOND, 0); ... |