This week's book giveaways are in the iOS and Features new in Java 8 forums.
We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Difference Between Dates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Barcodes with iOS this week in the iOS forum
or Core Java for the Impatient in the Java 8 forum!

JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Difference Between Dates" Watch "Difference Between Dates" New topic
Author

Difference Between Dates

Naadir Peterson
Ranch Hand

Joined: Sep 22, 2004
Posts: 37
What is the easiest way to calculate the difference, in hours, between two Dates?
eg : 12 December 2004 - 15:42 pm and 18 December 2004 - 11:36 am
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1824

Date has a .getTime() method, which returns the milliseconds representation of the time. calculate the millisecond difference, then divide by 3600000 to get difference in hours.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
sreelesh kumar
Greenhorn

Joined: Jan 03, 2005
Posts: 2
tell me how to convert 24jan2004 to 24/01/2004
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

The answer (or at least a hint) is with your post. Best not to cross post, its just confusing.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
jQuery in Action, 2nd edition
 
subject: Difference Between Dates