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: http://aspose.com/file-tools
subject: end of month calculation
Similar Threads
Switch with Boolean ???
Need help in data displaying
whats wrong with this code?? number of days in month..
Julian to Gregorian date conversion
Finding number of days in a month confusion