• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get the previous date

 
Makong
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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"
tanks.
 
Laurent S
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To format the date in your desired use the class SimpleDateFormat, for instance:
<code>
Date now = new Date();
SimpleDateFormat myTimeFormat = new SimpleDateFormat("yyyy-MM.dd");
String strDate = myTimeFormat.format(now);</code>
Look at http://java.sun.com/j2se/1.3/docs/api/java/text/SimpleDateFormat.html
Tom
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic