*
The moose likes Beginning Java and the fly likes Subtracting Date and Time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Subtracting Date and Time" Watch "Subtracting Date and Time" New topic
Author

Subtracting Date and Time

Tony May
Greenhorn

Joined: Jan 04, 2002
Posts: 17
Hi all..
I have two Date objects and need to find out the amount of time between them. Any ideas?
Jeff Wisard
Ranch Hand

Joined: Jan 07, 2002
Posts: 89
Use the getTime() method of Date to get 'long' representations of your dates (which is the number of milliseconds since the Jan. 1, 1970).
Then get the difference of these two numbers. This will be the number of milliseconds difference between your two dates. Divide the result by 1000, and you have the number of seconds between your dates....and so forth.
Hope this helps!
[ January 17, 2002: Message edited by: Jeff Wisard ]

Jeff Wisard<br />Sun Certified Java Programmer (Java 2)<br />Sun Certified Web Component Developer
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Subtracting Date and Time
 
Similar Threads
advanced calculator
What is the Data Type for GMT Date and Time?
displaying time
Date question
how to convert String into Date format