wood burning stoves 2.0*
The moose likes Java in General and the fly likes increasing the date in java as whole Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "increasing the date in java as whole" Watch "increasing the date in java as whole" New topic
Author

increasing the date in java as whole

rammie singh
Ranch Hand

Joined: Mar 26, 2009
Posts: 116
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

Joined: Apr 06, 2010
Posts: 4343
    
    8

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

Joined: Aug 18, 2009
Posts: 174

Add Calendar.DAY_OF_MONTH instead of Calendar.DATE
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

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

Joined: Oct 27, 2005
Posts: 19653
    
  18

The problem is in your formatter. "mm" means minutes; you need "MM" for months. Beaten to it when I was testing.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
rammie singh
Ranch Hand

Joined: Mar 26, 2009
Posts: 116
Thanks everybody.

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

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: increasing the date in java as whole
 
Similar Threads
Silly Date Problem
still stuck with "Failed to install HelloAndroid.apk on device" error
Multiple Sub-queries. efficient or not ?