Java Calendar date error

前端 未结 5 1934
栀梦
栀梦 2021-01-26 02:41

Can anyone please help me understand why I am getting different month values for

SimpleDateFormat dateFormat = new SimpleDateFormat(\"dd/MM/yyyy\");    
Syst         


        
5条回答
  •  太阳男子
    2021-01-26 02:59

    Your likely problem is that Calendar uses a zero-based index for months. So the format correctly outputs 9 for September, but the getter returns 8.

    Is this stupid and inconsistent of Calendar? Yes! Use the Joda-Time API for working with dates and times instead. As far as I'm aware, it's currently the de-facto standard until JSR 310 comes around.

提交回复
热议问题