Why does setting date with calendar give me the wrong date

前端 未结 3 1469
长发绾君心
长发绾君心 2021-01-24 07:20

I am setting the date to 2013-01-01 00:00:00, but the date comes out as Fri Feb 01 00:00:00 GMT+01:00 2013

Why?

Calendar calendar = Calendar.getInstance(         


        
3条回答
  •  臣服心动
    2021-01-24 07:31

    1 means Feburary. 0 is January. Months are indexed starting from 0. It's always better to use mnemonics: Calendar.JANUARY

提交回复
热议问题