Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

increasing the date in java as whole

 
rammie singh
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

How can we increase the date in java as whole. I mean to say that suppose my current date is 30/09/2011 then after increasing the date by 1 it should directly give 1/10/2011 not 31/09/2011 or if i increase by 2 it should give 02/10/2011 not 01/09/2011.
what i am trying is below. Is there any functions where month or year are automatically taken care off after increasing.



can any body please help me.
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First thing you need to do is get your format corrected:

- For day of the month, you need to use "MM", not "mm" ("mm" is for minute)
- If you're parsing a four-digit year, use "yyyy"

Fix those, and see if the problem still occurs.
 
Zandis Murāns
Ranch Hand
Posts: 174
Java Java ME Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add Calendar.DAY_OF_MONTH instead of Calendar.DATE
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zandis Murāns wrote:Add Calendar.DAY_OF_MONTH instead of Calendar.DATE

That won't make any difference. Look up Calendar.DATE in the docs and you get:
This is a synonym for DAY_OF_MONTH.
 
Rob Spoor
Sheriff
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is in your formatter. "mm" means minutes; you need "MM" for months. Beaten to it when I was testing.
 
rammie singh
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everybody.

The problem indeed was in selecting the format. i tried ("dd/MM/yyyy") and it is working.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic