0

How can I find the difference between two Dates in units of whole months, in Java?

anon
  • 1,101
  • 3
  • 17
  • 33

2 Answers2

4

Using JodaTime a lot of date/time functionality is a lot easier to implement:

http://joda-time.sourceforge.net/

there were plans to incorporate the library into Java 7, though this unfortunately did not happen:

Joda Time to be included in Java 7?

Community
  • 1
  • 1
davek
  • 22,499
  • 9
  • 75
  • 95
  • Most likely the new date and time API is going to be included in Java 8 - see [Project ThreeTen](http://threeten.sourceforge.net). – Jesper Sep 28 '12 at 09:36
2

I would strongly recommend looking at Joda-Time since it's a better, more-intuitive and thread-safe API. Check out this SO answer for a Joda-specific answer to your question.

Note that the Joda API was the foundation for the new Java Date API (JSR-310) and is scheduled for release in Java 8 (it got dropped from Java 7). It's a de facto standard and learning that API will be valuable.

Community
  • 1
  • 1
Brian Agnew
  • 268,207
  • 37
  • 334
  • 440