Java calendar get the current date, without hours, minutes, seconds and milliseconds, in milliseconds

后端 未结 5 1353
遥遥无期
遥遥无期 2020-12-14 17:32

I would like to get the current date in milliseconds with only year, month and date. But when I use this code:

Calendar cal = Calendar.getInstance();
cal.cle         


        
5条回答
  •  無奈伤痛
    2020-12-14 17:43

    from the javadoc: The HOUR_OF_DAY, HOUR and AM_PM fields are handled independently and the the resolution rule for the time of day is applied. Clearing one of the fields doesn't reset the hour of day value of this Calendar. Use set(Calendar.HOUR_OF_DAY, 0) to reset the hour value.

    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    

    might need to set AM/PM as well

提交回复
热议问题