Fastest way to get hour of java.util.date?

后端 未结 2 1091
隐瞒了意图╮
隐瞒了意图╮ 2021-01-18 05:30

When starting from ajava.util.date object: what is the best way getting the hour part as an integer regarding performance?

I have to iterat

2条回答
  •  暖寄归人
    2021-01-18 05:57

    In UTC:

    int hour = (int)(date.getTime() % 86400000) / 3600000;
    

    or

     long hour = (date.getTime() % 86400000) / 3600000;
    

提交回复
热议问题