JDK-4985363 : Changing Date to String and String to Date back couse loss of One Year
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2004-01-29
  • Updated: 2004-01-30
  • Resolved: 2004-01-30
Related Reports
Duplicate :  
Description
Changing Date to String and String to Date back using simpleDateFormat causes loss of One Year. 

Steps to reproduce:
--------------------
1) Compile and run the attached test case.
2) The output will show Delta of -364 days. 

Comments
EVALUATION The cause is execution order of Calendar.set() in SimpleDateFormat. ###@###.### 2004-01-30 The parse method sets the calendar field values in the order of items in the produced string "12-30-2002-Mon-04-07-50-089-AM-05-01-364-4-Monday-December" which includes multiple calendar fields. With the calendar field resolution rule, Calendar picks up WEEK_OF_YEAR and DAY_OF_WEEK. Monday of the 1st week of 2002 is December 31 2001. This is a known problem of GregorianCalendar that there's no way to specify week-based year numbers. I'm closing this bug as a duplicate of 4267450. ###@###.### 2004-01-30
30-01-2004