Why does this happens? For the month and day, I think Java is assuming the previous valid month and day, but I don't understand why year is 2.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
Date result = sdf.parse("0000/00/00");
System.out.println(result.toString());
Output is:
Sun Nov 30 00:00:00 GMT 2
The Gregorian calendar does not have year 0.
Year 0 corresponds to 1BCE (Before Common Era, also known as BC).
Because you supply 0 for the month and 0 for the day, it rolls back to the previous month and previous year.
I.e. 30-Nov-0002 BCE.
Date#toString
does not include BCE / CE suffix. It would be superfluous in the vast majority of cases.
If you are going to work with dates that far back then you need to consult with an historian.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With