Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

How to get past date ?  RSS feed

 
Greenhorn
Posts: 25
  • 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
 
Ranch Hand
Posts: 124
  • 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);
 
Ranch Hand
Posts: 183
  • 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
  • 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
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, Neil and John. I got all I wanted.
Lily
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!