Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

end of month calculation

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I'm looking for a method that returns the begining and end of next month.
example:

today is 2005-10-04

so the method suppose to return:
2005-11-01
&
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.
Thanks
Peter



 
Seb Mathe
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
creative, I like it.
thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic