JDK-6609728 : [Fmt-Da] invalid date comversion in SimpleDateFormat
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 5.0
  • Priority: P5
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-09-26
  • Updated: 2010-12-16
  • Resolved: 2010-12-16
Description
FULL PRODUCT VERSION :


A DESCRIPTION OF THE PROBLEM :
when I create a SimpleDateFormat with "yyyyMMdd" pattern and I use the parse(String string) method, whith string="00000000", the return value is "Sun Nov 30 00:00:00 CET 2". Why Nov 30 2 AD ???

ACTUAL -
Sun Nov 30 00:00:00 CET 2

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
SimpleDateFormat f = new SimpleDateFormat("yyyyMMdd");
		try {
			System.err.println(f.parse("00000000"));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
---------- END SOURCE ----------

Comments
EVALUATION 0000-00-00 is interpreted as one year before AD 1 which is BC 1, one month before January which is BC 2 December, and one day before the 1st which is BC 2 November 30. Also Date.toString() doesn't produce any era information. To deal with BC dates, use SimpleDateFormat with era information.
16-12-2010