• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how can i get previous date?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
reply
    Bookmark Topic Watch Topic
  • New Topic