This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting Last Date of Previous Month

 
ShivPrakash Srivastava
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How can I get the last date of the previous month in java ? For example if the date entered is 1/4/2007,the I should get the output as 31/3/2007.Code snippet for this would really help.

Thanks and Regards
Shiv
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Code snippet for this would really help

Well, in the big picture its going to help you less (see this)

Have a look at the Calendar class and notice that there are methods to rollback a calender by a particular amount for a particular field (minute, hour, day, year etc.). Also notice there are methods to get the maximum value a particular field can hold.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic