List of utility methods to do Day End
int | getMonths(Date end, Date start) get Months Calendar aCalendar = Calendar.getInstance(); Calendar bCalendar = Calendar.getInstance(); aCalendar.setTime(end); bCalendar.setTime(start); int months = 0; while (aCalendar.before(bCalendar)) { months++; aCalendar.add(Calendar.MONTH, 1); ... |
Integer | getMonthsBetweenBeginDateAndEndDate(Date beginDate, Date endDate) get Months Between Begin Date And End Date Calendar cal1 = Calendar.getInstance(); cal1.setTime(beginDate); Calendar cal2 = Calendar.getInstance(); cal2.setTime(endDate); int year = cal2.get(Calendar.YEAR) - cal1.get(Calendar.YEAR); int month = cal2.get(Calendar.MONTH) - cal1.get(Calendar.MONTH); month = year * 12 + month; month += 1; ... |
int | getMonthSpan(Date begin, Date end) get Month Span Calendar beginCal = new GregorianCalendar(); beginCal.setTime(begin); Calendar endCal = new GregorianCalendar(); endCal.setTime(end); int m = (endCal.get(Calendar.MONTH)) - (beginCal.get(Calendar.MONTH)); int y = (endCal.get(Calendar.YEAR)) - (beginCal.get(Calendar.YEAR)); return y * 12 + m; |
int | getMonthSpan(Date start, Date end) This method returns the number of months between the specified dates. GregorianCalendar first = createCalendar(start); GregorianCalendar last = createCalendar(end); int monthSpan = 0; first.set(DAY_OF_MONTH, 1); monthSpan += (last.get(MONTH) - first.get(MONTH)); monthSpan += 12 * (last.get(YEAR) - first.get(YEAR)); if (monthSpan < 0) { monthSpan = 0; ... |
long | getMsBetween(Date startDate, Date endDate) get Ms Between Calendar cal = getCalendar(); cal.setTime(startDate); long startMs = cal.getTimeInMillis(); cal.setTime(endDate); long endMs = cal.getTimeInMillis(); return endMs - startMs; |
Date | getNextEndDate(Date date, int offset) get Next End Date if (offset < 1) { return date; } else { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); for (int dayOfWeek = calendar.get(7); offset > 0; --offset) { if (dayOfWeek == 6) { calendar.add(5, 3); ... |
Date | getNextSendTime(Date sendDate, Date start) get Next Send Time Calendar calendar = Calendar.getInstance(); if (sendDate != null) { calendar.setTime(sendDate); Calendar startCalendar = Calendar.getInstance(); if (start == null) { startCalendar.set(Calendar.HOUR_OF_DAY, 8); startCalendar.set(Calendar.MINUTE, 0); ... |
Integer | getNumberOfDaysBetweenDates(Date beginDate, Date endDate) get Number Of Days Between Dates Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); c1.setTime(beginDate); c2.setTime(endDate); long timeBetweenInMillis = c2.getTimeInMillis() - c1.getTimeInMillis(); Integer numberDaysBetweenDates = new Integer(new Long(timeBetweenInMillis / (3600000 * 24)).intValue()); return numberDaysBetweenDates; |
int | getNumberOfMonthsBetween(final Date begin, final Date end) get Number Of Months Between if (begin == null || end == null) return -1; Calendar cal1 = Calendar.getInstance(); cal1.setTime(begin); Calendar cal2 = Calendar.getInstance(); cal2.setTime(end); return (cal2.get(Calendar.YEAR) - cal1.get(Calendar.YEAR)) * 12 + (cal2.get(Calendar.MONTH) - cal1.get(Calendar.MONTH)); ... |
int | getNumMonths(Date dStart, Date dEnd) Gets the number of months between two date objects int i = 0; Calendar calendar = Calendar.getInstance(); calendar.setTime(dStart); while (calendar.getTime().before(dEnd) || calendar.getTime().equals(dEnd)) { calendar.add(Calendar.MONTH, 1); i++; i--; ... |