Calendar.MONTH gives wrong value

后端 未结 6 1959
醉酒成梦
醉酒成梦 2020-12-19 01:14

I\'m trying to get the actual month from the Calendar using the following:

Calendar c = Calendar.getInstance();          
String time = String.v         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-19 01:24

    Calendar.MONTH

    returns

    0 for 1st month (jan)
    1 for 2nd month (feb)
    .
    .
    11 for 12th month (dec)
    

    Docs

    So change your code to

    String time = String.valueOf(c.get(Calendar.MONTH)+1);// added 1 
    

提交回复
热议问题