File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Get the previous date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Get the previous date" Watch "Get the previous date" New topic

Get the previous date


Joined: Oct 18, 2001
Posts: 2
i just want to know how can i get the previous date, let's say the date of yesterday.. like this:
yesterday is "2001-10-19"
Laurent S

Joined: Sep 27, 2001
Posts: 15
You can work with the class Date
public Date Yesterday(Date d) { return new Date(d.getTime() - (24*60*60*1000));}
Thomas Suer
Ranch Hand

Joined: Sep 03, 2001
Posts: 50
To format the date in your desired use the class SimpleDateFormat, for instance:
Date now = new Date();
SimpleDateFormat myTimeFormat = new SimpleDateFormat("yyyy-MM.dd");
String strDate = myTimeFormat.format(now);</code>
Look at
I agree. Here's the link:
subject: Get the previous date
It's not a secret anymore!