| 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: 19216
|
|
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
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: how can i get previous date?
|
|
|