This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get past date ?

 
lily ling
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, there
I want to get the date which is 80 days before certain date ( let's say today ), may I ask how to compute that date ?
Thanks in advance,
Lily
 
john guthrie
Ranch Hand
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd use simple math:
long now = System.currentTimeMillis();
long eightyDays = (long)80 * 24 * 60 * 60 * 1000;
Date then = new Date(now-eightyDays);
 
Neil Laurance
Ranch Hand
Posts: 183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you can use the Calendar class:

Cheers, Neil
 
lily ling
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.
Yes, by using Calendar ( the second way ), I could print out the time I want ( 80 days ago, let's say ). If I want to know if a Date obj passed in is before this Calendar date, how to convert that Date obj to a Calendar obj so that I could use CalendarObj.before( passed_in_Date_to_CalendarObj ) to do the comparison ?
Tons of thanks,
Lily
 
Neil Laurance
Ranch Hand
Posts: 183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Calendar instance method getTime() returns a java.util.Date so you readily compare the 2, for example:

Returns:

21-05-2002 before 09-08-2002 = true
21-05-2002 before 09-08-2002 = true

Cheers Neil
 
lily ling
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, Neil and John. I got all I wanted.
Lily
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic