Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate Tomorrow and Yesterday

Status
Not open for further replies.

beanNut

IS-IT--Management
Jun 2, 2004
28
US
Can someone provide a snippet for calculating Tomorrow and also Yesterday? Having trouble with this - not as simple as I thought??
 
What did you try so far?

There must be easier and more accurate ways, that look at Calendar class, for instance, but I can think on this:

Code:
long oneDay = (long) 1000.0 * 60 * 60 * 24;

java.util.Date tomorrow = new java.util.Date(System.currentTimeMillis()+oneDay);

java.util.Date today = new java.util.Date(System.currentTimeMillis());

java.util.Date yesterday = new java.util.Date(System.currentTimeMillis()-oneDay);

Btw, I think the roght forum to post this is the Java forum.

Cheers,

Dian
 
You could do something like:-
Code:
Calendar cal1 = Calendar.getInstance();
cal1.add(Calendar.DATE, 1); //For tomorrow

Calendar cal2 = Calendar.getInstance();
cal2.add(Calendar.DATE, -1); //For yesterday

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top