Java getHours(), getMinutes() and getSeconds()

后端 未结 3 914
离开以前
离开以前 2020-12-02 16:29

As I know getHours(), getMinutes() and getSeconds() are all deprecated in Java and they are replaced with Calendar.HOUR_OF_DAY

3条回答
  •  误落风尘
    2020-12-02 16:52

    Try this:

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(yourdate);
    int hours = calendar.get(Calendar.HOUR_OF_DAY);
    int minutes = calendar.get(Calendar.MINUTE);
    int seconds = calendar.get(Calendar.SECOND);
    

    Edit:

    hours, minutes, seconds
    

    above will be the hours, minutes and seconds after converting yourdate to System Timezone!

提交回复
热议问题