• 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

Getting yesterday's date ......

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
in my code i am doing this:
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
The second line sets the time as the default date which is todays date.
Please, how do i set yesterday's date
That is :
Calendar cal = Calendar.getInstance();
cal.setTime( ....yesterday's date );
Code snippet will be appreciated.
Thank you.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would be a good idea to at least take a look at the Java API documentation before posting trivial questions in the advanced forum.
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try using java.utils.Calendar.add()


add
public abstract void add(int field, int amount)
Date Arithmetic function. Adds the specified (signed) amount of time to the given time field, based on the calendar's rules. For example, to subtract 5 days from the current time of the calendar, you can achieve it by calling:
add(Calendar.DATE, -5).

Parameters:
    field - the time field.
    amount - the amount of date or time to be added to the field.


Also, I'm moving this to the intermediate forum, seeing as though its not an advanced question.
[ May 10, 2004: Message edited by: Jessica Sant ]
 
Gabriel Tomoloju
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jessica, i will try that.
Sorry Joe, i know this is very trivial, but i thought it will be of no use
saying how much i have researched into solving this.
It is a simple logic behind a complex enterprise application.
I have been checking the java.util.Date API doc for this.
Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic