This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Java in General and the fly likes need clever date difference methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "need clever date difference methods" Watch "need clever date difference methods" New topic
Author

need clever date difference methods

Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4659
    
    5

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

Joined: May 03, 2008
Posts: 4986
    
    8

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.


luck, db
There are no new questions, but there may be new answers.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: need clever date difference methods
 
It's not a secret anymore!