aspose file tools*
The moose likes Java in General and the fly likes API methods for difference between two dates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "API methods for difference between two dates" Watch "API methods for difference between two dates" New topic
Author

API methods for difference between two dates

Peter Braun
Ranch Hand

Joined: Feb 09, 2005
Posts: 57
Somebody please tell me why don't create the Sun create methods for calculate difference between two dates? Days between two dates for example.

Thanks,
Peter
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14420
    
  23

I don't know why Sun didn't add that to the standard library. But calculating the difference between to dates is easy. You just look at the millisecond values of your two Date objects and subtract them - then you have the difference in milliseconds. It's straightforward to convert this to days (just divide by 24 * 60 * 60 * 1000, which is the number of milliseconds in one day).


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
Consider Paul's rocket mass heater.
 
subject: API methods for difference between two dates