[Logo]
Forums Register Login
dates in java
How to get previous days date in java. i.e. current date-1
Hi
I use the Calendar class as all familiar Date Constructor/methods are deprecated.

This backs up the calendar one day.
The Java 2 API docs are pretty good in showing how to use this class.
Hope this helped.
import java.util.Date;
import java.util.Calendar;
public class Prev
{
public static void main(String args[])
{
Calendar xx = Calendar.getInstance();
Date dt = null;
xx.add(Calendar.DATE,-1);
dt = xx.getTime();
System.out.println("Yesterday Is : " + dt.getDate());
}
}

This thread has been viewed 984 times.

All times above are in ranch (not your local) time.
The current ranch time is
Dec 18, 2018 20:57:01.