Why does a new SimpleDateFormat object contain calendar with the wrong year?

后端 未结 5 584
暖寄归人
暖寄归人 2020-12-20 15:54

I came upon a strange behavior that has left me curious and without a satisfactory explanation as yet.

For simplicity, I\'ve reduced the symptoms I\'ve noticed to th

5条回答
  •  一整个雨季
    2020-12-20 16:15

    Looking through SimpleDateFormat it seems like it's something to do with serialization:

    /* Initialize the fields we use to disambiguate ambiguous years. Separate
     * so we can call it from readObject().
     */
    private void initializeDefaultCentury() {
        calendar.setTime( new Date() );
        calendar.add( Calendar.YEAR, -80 );
        parseAmbiguousDatesAsAfter(calendar.getTime());
    }
    

提交回复
热议问题