Java Date Previous getPreviousDay(Date date)

Here you can find the source of getPreviousDay(Date date)

Description

Get the previous day date-time relative to the provided current date-time.

License

Open Source License

Parameter

Parameter Description
date The current date-time

Return

The previous day's date-time

Declaration

public static Date getPreviousDay(Date date) 

Method Source Code

//package com.java2s;
//file LICENSE in the root of the DomainHealth distribution.

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class Main {
    /**//from   w  w  w . java 2  s. co m
     * Get the previous day date-time relative to the provided current 
     * date-time.
     * 
     * @param date The current date-time
     * @return The previous day's date-time
     */
    public static Date getPreviousDay(Date date) {
        return getNthPreviousDay(date, 1);
    }

    /**
     * Get the date-time of Nth day previous to the provided current date-time.
     * 
     * @param date The current date-time
     * @param numDaysPrevious The number of days back to go
     * @return The date-time of the Nth day previous to the provide date-time
     */
    public static Date getNthPreviousDay(Date date, int numDaysPrevious) {
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_YEAR, (0 - numDaysPrevious));
        return calendar.getTime();
    }
}

Related

  1. getPrevDueDate(int payperiod, long time)
  2. getPreviousDate(Date date)
  3. getPreviousDate(final Date date)
  4. getPreviousDate(int period)
  5. getPreviousDateStart()
  6. getPreviousDay(Date dateTime)
  7. getPreviousDay(Date inputDate)
  8. getPreviousFriday(final Date d)
  9. getPreviousMonday(Date day)