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 end of month calculation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Java in General
Bookmark "end of month calculation" Watch "end of month calculation" New topic

end of month calculation

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Hi all,
I'm looking for a method that returns the begining and end of next month.

today is 2005-10-04

so the method suppose to return:
2005-11-31 //as it ends on the 31

I came up with the code below - but I don't like it as I can't get the end of month + it's not safe.

any suggestions.

Seb Mathe
Ranch Hand

Joined: Sep 28, 2005
Posts: 225
Use Calendar.add() and Calendar.set() methods.

Set the day-of_month field to one
Add one month
Add one month and remove one day !

Regards,<br />Seb<br /> <br />SCJP 1.4
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
creative, I like it.
I agree. Here's the link:
subject: end of month calculation
It's not a secret anymore!