File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Murach's Java Servlets and JSP this week in the Servlets 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

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.

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074

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 7 API documentation
Scala Notes - My blog about Scala
I agree. Here's the link:
subject: API methods for difference between two dates
Similar Threads
Problem in setting the date in a servlet
How to calculate difference between two dates in months
difference between two dates
DateDiff Function in Java?
how to get date month year time