List of utility methods to do Day End
long | getMinllisBetween(Date beginDate, Date endDate) get Minllis Between Calendar d1 = new GregorianCalendar(); d1.setTime(beginDate); Calendar d2 = new GregorianCalendar(); d2.setTime(endDate); if (d1.after(d2)) { return 0; long minllis = d2.getTimeInMillis() - d1.getTimeInMillis(); ... |
List | getMondays(Date startDate, Date endDate) get Mondays if (endDate != null && !startDate.before(endDate)) { throw new RuntimeException("startDate must before endDate."); List<Date> mondayList = new ArrayList<Date>(); Date previousMonday = getPreviousMonday(endDate); for (; !previousMonday.before(startDate); previousMonday = getPreviousMonday(previousMonday)) { mondayList.add(previousMonday); return mondayList; |
Integer | getMonthBetween(Date startDate, Date endDate) get Month Between if (startDate == null || endDate == null || !startDate.before(endDate)) { return null; Calendar start = Calendar.getInstance(); start.setTime(startDate); Calendar end = Calendar.getInstance(); end.setTime(endDate); int year1 = start.get(Calendar.YEAR); ... |
int | getMonthCha(Date start, Date end) get Month Cha Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); c1.setTime(start); c2.setTime(end); int y1 = c1.get(Calendar.YEAR); int y2 = c2.get(Calendar.YEAR); int m1 = c1.get(Calendar.MONTH); int m2 = c2.get(Calendar.MONTH); ... |
int | getMonthCount(Date startDate, Date endDate) Return month count. int count = 1; Calendar calendar = Calendar.getInstance(); calendar.setTime(endDate); count += calendar.get(Calendar.YEAR) * 12 + calendar.get(Calendar.MONTH); calendar.setTime(startDate); count -= calendar.get(Calendar.YEAR) * 12 + calendar.get(Calendar.MONTH); return count; |
Date | getMonthEnd(Date date) get Month End Calendar calendar = Calendar.getInstance(); calendar.setTime(date); calendar.add(Calendar.MONTH, 1); int index = calendar.get(Calendar.DAY_OF_MONTH); calendar.add(Calendar.DATE, (-index)); return calendar.getTime(); |
Date | getMonthEndDate(Date date) get Month End Date GregorianCalendar c = new GregorianCalendar(); c.setTime(date); int maxMonth = c.getActualMaximum(Calendar.DAY_OF_MONTH); c.set(Calendar.DAY_OF_MONTH, maxMonth); c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 59); c.set(Calendar.SECOND, 59); return c.getTime(); ... |
Date | getMonthEndDate(int year, int month) get Month End Date Calendar c = Calendar.getInstance();
c.set(Calendar.YEAR, year);
c.set(Calendar.MONTH, month);
c.set(Calendar.DAY_OF_MONTH, 0);
c.set(Calendar.HOUR_OF_DAY, 23);
c.set(Calendar.MINUTE, 59);
c.set(Calendar.SECOND, 59);
return c.getTime();
...
|
Long | getMonthEndDate(Long day) get Month End Date Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(day); int end = cal.getActualMaximum(Calendar.DATE); cal.set(Calendar.DATE, end); return cal.getTimeInMillis(); |
List | getMonthFirstDays(Date startDate, Date endDate) get Month First Days if (endDate != null && !startDate.before(endDate)) { throw new RuntimeException("startDate must before endDate."); List<Date> monthFirstDayList = new ArrayList<Date>(); Date previousMonthFirstDay = getPreviousMonthFirstDay(endDate); for (; !previousMonthFirstDay .before(startDate); previousMonthFirstDay = getPreviousMonthFirstDay(previousMonthFirstDay)) { monthFirstDayList.add(previousMonthFirstDay); ... |