什么是HOUR_OF_DAY的范围? [英] what is the range of HOUR_OF_DAY?
问题描述
有一个简单的问题,但我无法找到它:
时HOUR_OF_DAY的0至23,或1和24之间的范围内
我想一个随机HOUR_OF_DAY,我需要:
INT randomHour =(INT)(的Math.random()* 24);
或
INT randomHour =(INT)(的Math.random()* 24 + 1);
从的文档:
有关获取设置指示一天中的小时数场和。
HOUR_OF_DAY
用于24小时制。例如,在10:04:15.250 PM的HOUR_OF_DAY
22
块引用>如果10:04:15.250 PM是
HOUR_OF_DAY
22,这将使范围0
-23
。如果是1
到24
10时是23,这将是错误的这么多层次。 : - )A simple question, but i couldn't find it:
Is the range of HOUR_OF_DAY between 0 and 23, or 1 and 24?
I want a random HOUR_OF_DAY, do I need:
int randomHour = (int) (Math.random()*24);
or
int randomHour = (int) (Math.random()*24+1);
解决方案From the documentation:
Field number for get and set indicating the hour of the day.
HOUR_OF_DAY
is used for the 24-hour clock. E.g., at 10:04:15.250 PM theHOUR_OF_DAY
is 22.If 10:04:15.250 PM is
HOUR_OF_DAY
22, That would make the range0
-23
. If it were1
to24
, 10 p.m. would be 23. And that would be wrong on so many levels. :-)这篇关于什么是HOUR_OF_DAY的范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!