Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date for last month

 
sam davis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Could someone help me out with the code to get the date for one month ago(last month)...and how would i account for the date rollover(when the year changes) i would really appreciate it..thanks..
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use java.util.Calendar to accomplish this.
 
sam davis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joel for your help. However, i found roll() method to be better. Appreciate your help ..
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...But roll won't change the year!
From the
documentation

Example: Consider a GregorianCalendar originally set to August 31, 1999. Calling roll(Calendar.MONTH, 8) sets the calendar to April 30, 1999. Using a GregorianCalendar, the DAY_OF_MONTH field cannot be 31 in the month April. DAY_OF_MONTH is set to the closest possible value, 30. The YEAR field maintains the value of 1999 because it is a larger field than MONTH.

[ July 09, 2003: Message edited by: Joel McNary ]
 
sam davis
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Joel,
You are right..I'm sorry but i don't think i was clear about my response..i was talking about changing month...thats what i used roll() for..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic