Java Calendar Setting Incorrectly

前端 未结 6 1360
离开以前
离开以前 2021-01-25 13:34

I\'m having some trouble with Java\'s Calendar. I\'m parsing some data from a txt file, and need to create a date. After completion of the following code:

tmpYea         


        
6条回答
  •  温柔的废话
    2021-01-25 13:54

    The reason is quite simple: design fault in the Calendar API. That's why the JSR 310 is on its way in order to improve the java support for dates.

    Technically, the authors of the class thought it was good to use only static fields. So what you need to do is to use the following:

    calendar = ...
    calendar.setMonth(Calendar.JANUARY);
    

    They didn't think that people might need dynamic settings to a calendar, just like you need (and most of us, for that matters).

提交回复
热议问题