Hi,
I want to find out the elapsed date for example, if I have two dates I want to find out the difference between them in days. Can this be done? If yes can anyone send me the code this is really urgent.
Sarvesh
-
Elapsed Date (2 messages)
- Posted by: sarvesh naidu
- Posted on: July 22 2003 23:45 EDT
Threaded Messages (2)
- Elapsed Date by Raffi Basmajian on July 23 2003 08:14 EDT
- Elapsed Date by Paul Strack on July 23 2003 09:12 EDT
-
Elapsed Date[ Go to top ]
- Posted by: Raffi Basmajian
- Posted on: July 23 2003 08:14 EDT
- in response to sarvesh naidu
This is a very easy problem. If you have two dates, and you know the date that occurs later, simply subtract the time of the other date from the later date.
Date now = new Date(System.currentTimeMillis());
Date later = new Date(System.currentTimeMillis());
long diff = later.getTime() - now.getTime();
You can divide 'diff' by the number of milliseconds per day, to get the difference in days, or by the number of milliseconds per hour, to get the differnce in hours, etc, you get the idea.
Raffi -
Elapsed Date[ Go to top ]
- Posted by: Paul Strack
- Posted on: July 23 2003 09:12 EDT
- in response to Raffi Basmajian
If using the precise difference in milliseconds won't work for you, there are utility methods in the java.util.Calendar class for determine the difference between two dates.