Java Utililty Methods Date Previous

List of utility methods to do Date Previous

Description

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

Method

DategetPreDay(Date date)
get Pre Day
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(Calendar.DATE, -1);
return c.getTime();
DategetPrefixStartDate(Integer day)
get Prefix Start Date
Date date = new Date();
if (day == null) {
    return date;
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, -day);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
...
DateGetPreMonthBeginDate()
Get Pre Month Begin Date
Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH, -1);
c.set(Calendar.DAY_OF_MONTH, c.getActualMinimum(Calendar.DAY_OF_MONTH));
return c.getTime();
DategetPreMonthDate(Date date, int month)
get the previos n month
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) - month, calendar.get(Calendar.DATE),
        0, 
        0, 
        0); 
calendar.clear(Calendar.MILLISECOND);
return calendar.getTime();
...
DategetPrevDay(Date date)
get Prev Day
if (date == null) {
    throw new NullPointerException();
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
calendar.add(Calendar.DAY_OF_YEAR, -1);
return calendar.getTime();
DategetPrevDueDate(int payperiod, long time)
get Prev Due Date
Calendar now = Calendar.getInstance();
now.setTimeInMillis(time);
if (payperiod == 1) {
    now.add(Calendar.MONTH, -1);
} else if (payperiod == 2) {
    now.add(Calendar.MONTH, -3);
} else if (payperiod == 3) {
    now.add(Calendar.MONTH, -6);
...
DategetPreviousDate(Date date)
Get the previous date
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(java.util.Calendar.DAY_OF_YEAR, -1);
return calendar.getTime();
DategetPreviousDate(final Date date)
Get the date for the day previous to that specified.
return getOffsetDate(date, -1, Calendar.DATE);
DategetPreviousDate(int period)
get Previous Date
Date today = new Date();
Calendar calendar = new GregorianCalendar();
calendar.setTime(today);
if (period == 7) {
    calendar.add(Calendar.DATE, -7);
} else if (period == 30) {
    calendar.add(Calendar.MONTH, -1);
} else {
...
DategetPreviousDateStart()
get Previous Date Start
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -2);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();