How to set time to 24 hour format in Calendar

后端 未结 9 1439
迷失自我
迷失自我 2020-12-25 12:10

I need to set the time on the current date. The time string is always in 24 hour format but the result I get is wrong:

  SimpleDateFormat df = new SimpleDate         


        
9条回答
  •  庸人自扰
    2020-12-25 12:46

    Replace this:

    c1.set(Calendar.HOUR, d1.getHours());
    

    with this:

    c1.set(Calendar.HOUR_OF_DAY, d1.getHours());
    

    Calendar.HOUR is strictly for 12 hours.

提交回复
热议问题