File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how can i get previous date?

 
prasant sahoo
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic