Java Utililty Methods Date Before

List of utility methods to do Date Before

Description

The list of methods to do Date Before are organized into topic(s).

Method

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());
...
DategetMonthBefore(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();
longgetMonthStartDateBeforeCurrent(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);
...
DategetOneHourBefore(Date date)
get One Hour Before
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(Calendar.HOUR_OF_DAY, -1);
return cal.getTime();
intgetPassedMonthBetweenDate(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);
CalendargetPreviousDate(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;
longgetQuarterStartDateBeforeCurrent(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: {
...
DategetSomeDaysBeforeAfter(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();
booleanisAtLeastOneDayBefore(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);
booleanisBefore(Date date)
is Before
return getCurrentDateTime().before(date);