File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
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