How to get previous Day Date in java

This example show you how to get the last day date using current date in java, you need to add the -1 in current date as DAY_OF_YEAR as shown in below example.

package com.java.connect.date;
 
import java.util.Calendar;
 
public class PreviousDayDateExample {
    public static void main(String[] args) {
        //
        // Get a calendar instance
        //
        Calendar originalDate = Calendar.getInstance();
        //
        // Print the original date
        //
        System.out.println("The original date is : " + originalDate.getTime());
        //
        // Get the clone of original date.
        //
        Calendar previousDay = (Calendar) originalDate.clone();
        // Add the -1 in Current Date as DAY OF YEAR
        previousDay.add(Calendar.DAY_OF_YEAR, -1);
        System.out.println("The previous Day date is: " + previousDay.getTime());
    }
}

The output of the above example will be as:

The original date is : Sat May 07 17:22:56 GMT 2011
The previous Day date is : Fri May 06 17:22:56 GMT 2011