• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

How to get past date ?

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or you can use the Calendar class:

Cheers, Neil
 
lily ling
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot, Neil and John. I got all I wanted.
Lily
reply
    Bookmark Topic Watch Topic
  • New Topic