This week's book giveaway is in the Testing forum.We're giving away four copies of The Way of the Web Tester: A Beginner's Guide to Automating Tests and have Jonathan Rasmusson on-line!See this thread for details.
Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# need clever date difference methods

Pat Farrell
Rancher
Posts: 4678
7
I've got to do a fair number of date/calendar calculations using the number of months or weeks between dates. With either Date or Calendar objects, its trivial to get the number of days between to objects, but how do you get the number of months? How do you get the number of weeks? Clearly any discussion of months really requires a Calendar, and in this case, I can easily use a GregorianCalendar

Suppose you have two dates, say October 16, 2012 and January 3, 2012. How many months are they appart?
How do I calculate that they are 41 weeks apart? How can I figure out how many Tuesdays are between them?

Darryl Burke
Bartender
Posts: 5148
11
I've never had occasion to use Joda Time, but I believe it has an Interval class that may (or may not!) be useful here.

edit A quick glance at the JavaDocs suggests that Duration and/or Period may be the useful classes -- not Interval.