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

add day to Date using Calendar.add() question

 
Andreas Markitanis
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone

I have been trying the following:



My question is how can i make it print 01/08/2010?I googled online but couldn't find anything....

anyone can point me in the right direction??

Thank you very much
 
Matthew Brown
Bartender
Posts: 4565
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, a common mistake.

Check the SimpleDateFormat docs, and you'll see:

m = Minute in hour
M = Month in year
 
Vinoth Kumar Kannan
Ranch Hand
Posts: 276
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try, Calendar's set(int field, int value) method?
That might help.
Set your month to 8 or do a month = month+1.
Just see the APIs, you'll get it for yourself.
 
Andreas Markitanis
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:Ah, a common mistake.

Check the SimpleDateFormat docs, and you'll see:

m = Minute in hour
M = Month in year


ah thanks Matthew! problem solved ;-)

I knew that MM is months but probably didn't realize at the time.



 
Vinoth Kumar Kannan
Ranch Hand
Posts: 276
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops...my interpretation of the posted prob was entirely wrong..!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic