Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.util.Calendar calculates wrong date when any duration is added

rahulkb007-JavaNetJan 9 2012 — edited Jan 10 2012
Hi friends,
I am trying to calculate the date through java.util.Calendar object and getting wrong value. Let me explain the scenario -

Scenario1:
I have taken start date and added some duration to that and expecting a new date which should be calculated as (start date+ duration). The value is as below -

start date = 2012-01-09 (9 January 2012 )
duration = 1year, 1month, 20 days
new date = 2013-02-28 ( 28 February 2013)

*Here new date I am expecting is 2013-03-01 (1 March 2013).

Scenario2:
I have taken another set of values as below -

start date = 2011-02-15 (15 February 2011)
duration = 1year, 1month, 15days
new date = 2012-03-30 (30 March 2012)

*Here new date is as expected.

Scenario1 data is giving me wrong result. Please let me know if any more information is required. Any help will be appriciated. Thanks in advance.

Edited by: user560316 on ९ जनवरी, २०१२ ६:२३ अपराह्न

Edited by: user560316 on ९ जनवरी, २०१२ ६:२४ अपराह्न
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 7 2012
Added on Jan 9 2012
8 comments
2,906 views