Here you can find the source of getPreviousDay(Date date)
Parameter | Description |
---|---|
date | The current date-time |
public static Date getPreviousDay(Date date)
//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(); } }