List of utility methods to do Date Before
Date[] | getMonth(Date time, int monthBefore, int monthAfter) get Month ArrayList result = new ArrayList(); Calendar calendar = Calendar.getInstance(); if (null != time) { calendar.setTimeInMillis(time.getTime()); for (int i = monthBefore; i <= monthAfter; i++) { Calendar calendartmp = Calendar.getInstance(); calendartmp.setTimeInMillis(calendar.getTimeInMillis()); ... |
Date | getMonthBefore(Date currentDate, int numberMonthBefore) get Month Before Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, currentDate.getYear() + 1900);
calendar.set(Calendar.MONTH, currentDate.getMonth() + 1 - numberMonthBefore);
calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE));
return calendar.getTime();
|
long | getMonthStartDateBeforeCurrent(int monthNum, Date current) get Month Start Date Before Current Calendar calendar = Calendar.getInstance(); calendar.setTime(current); calendar.set(Calendar.DAY_OF_MONTH, 1); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); calendar.add(Calendar.MONTH, -monthNum); ... |
Date | getOneHourBefore(Date date) get One Hour Before GregorianCalendar cal = new GregorianCalendar(); cal.setTime(date); cal.add(Calendar.HOUR_OF_DAY, -1); return cal.getTime(); |
int | getPassedMonthBetweenDate(Date before, Date after) get Passed Month Between Date Calendar c1 = Calendar.getInstance(); Calendar c2 = Calendar.getInstance(); c1.setTime(after); c2.setTime(before); int result = c2.get(Calendar.MONTH) - c1.get(Calendar.MONTH); return result == 0 ? 1 : Math.abs(result); |
Calendar | getPreviousDate(String before) This method gets the past dates based on the no. int beforeInt = 0 - Integer.valueOf(before); Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, beforeInt); return cal; |
long | getQuarterStartDateBeforeCurrent(int num, Date current) get Quarter Start Date Before Current Calendar calCurrent = Calendar.getInstance(); calCurrent.setTime(current); int currentMonth = calCurrent.get(Calendar.MONTH) + 1; Calendar latestQuarter = Calendar.getInstance(); switch (currentMonth) { case 1: case 2: case 3: { ... |
Date | getSomeDaysBeforeAfter(Date date, int days) get Some Days Before After GregorianCalendar gc = new GregorianCalendar(); gc.setTime(date); gc.add(5, days); gc.set(gc.get(Calendar.YEAR), gc.get(Calendar.MONTH), gc.get(Calendar.DATE)); return gc.getTime(); |
boolean | isAtLeastOneDayBefore(Date daybefore, Date dayafter) is At Least One Day Before Calendar calBefore = Calendar.getInstance();
Calendar calAfter = Calendar.getInstance();
calBefore.setTime(daybefore);
calAfter.setTime(dayafter);
return calBefore.get(Calendar.YEAR) == calAfter.get(Calendar.YEAR)
&& calBefore.get(Calendar.DAY_OF_YEAR) + 1 <= calAfter.get(Calendar.DAY_OF_YEAR);
|
boolean | isBefore(Date date) is Before return getCurrentDateTime().before(date);
|