This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes how can i get previous date? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how can i get previous date?" Watch "how can i get previous date?" New topic
Author

how can i get previous date?

prasant sahoo
Greenhorn

Joined: Dec 14, 2007
Posts: 7
Hi,
I am entering a future date,lets say(20-08-2008) through my application.I need to perform some actions on the previous date(19-08-2008) of the entered date(20-08-2008).How can i get that previous date? please help..
Rameshwar Kharat
Greenhorn

Joined: Mar 17, 2008
Posts: 3
Try GregorianCalendar
http://www.developer.com/java/article.php/732511
when dealing with the Dates

eg.
code to get yesterday's date using gregorian Calendar

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
GregorianCalendar today = new GregorianCalendar();
GregorianCalendar yesterday = new GregorianCalendar();
yesterday.add(Calendar.DATE, -1);
String yesDate = new String(yesterday.toString());
System.out.println(yesDate);

Hope this will help you .
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

I'd use Calendar.getInstance() instead of GregorianCalendar. That way you always get the calendar system of the local system; for some countries it may be different.


You can create a Calendar object for a specific date quite easily too:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: how can i get previous date?