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

DategetPreviousDay(Date date)
Get the previous day date-time relative to the provided current date-time.
return getNthPreviousDay(date, 1);
DategetPreviousDay(Date dateTime)
get Previous Day
return addDay(dateTime, -1);
DategetPreviousDay(Date inputDate)
get Previous Day
Calendar calendar = getCalendar(inputDate);
calendar.add(Calendar.DAY_OF_MONTH, -1);
return calendar.getTime();
DategetPreviousFriday(final Date d)
Finds the Friday preceding the date.
Calendar cal = getStockExchangeCalendar();
cal.setTime(d);
int dow = cal.get(Calendar.DAY_OF_WEEK);
cal.add(Calendar.DAY_OF_WEEK, -(dow + 1) % 7);
return cal.getTime();
DategetPreviousMonday(Date day)
get Previous Monday
Calendar previousMonday = Calendar.getInstance();
previousMonday.setTime(day);
previousMonday.set(Calendar.HOUR_OF_DAY, 0);
previousMonday.set(Calendar.MINUTE, 0);
previousMonday.set(Calendar.SECOND, 0);
previousMonday.add(Calendar.DATE, -1);
previousMonday.add(Calendar.WEEK_OF_MONTH, -1);
previousMonday.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
...
DategetPreviousMonth(Date time)
get Previous Month
Calendar calendar = Calendar.getInstance();
if (null != time) {
    calendar.setTimeInMillis(time.getTime());
calendar.add(Calendar.MONTH, -1);
return new Date(calendar.getTimeInMillis());
longgetPreviousMonth(long date)
Returns the previous month.
return incrementMonth(date, -1);
DategetPreviousMonthFirst(Date appointDate)
get Previous Month First
Calendar appointCalendar = Calendar.getInstance();
appointCalendar.setTime(appointDate);
Calendar lastDate = Calendar.getInstance();
lastDate.set(Calendar.DATE, 1);
lastDate.set(Calendar.MONTH, appointCalendar.get(Calendar.MONTH) - 1);
lastDate.set(Calendar.YEAR, appointCalendar.get(Calendar.YEAR));
return lastDate.getTime();
DategetPreviousQuarterStartDate(Date dt)
Gets the start date for the previous quarter
Calendar cal = Calendar.getInstance();
cal.setTime(dt);
int calMonth = cal.get(Calendar.MONTH);
int calMonthMod = (calMonth) % 3;
cal.add(Calendar.MONTH, -(calMonthMod + 3));
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
return dayStart(cal.getTime());
DategetPreviuosRoundMonth(Date baseDate)

Description:Get the date after the base date passed in as first parameter and interval is specified by second parameter

Calendar calendar = Calendar.getInstance();
calendar.setTime(baseDate);
calendar.set(Calendar.DATE, 1);
calendar.set(Calendar.HOUR, 0);
calendar.set(Calendar.MINUTE, 0);
Date resultDate = calendar.getTime();
return resultDate;