一个简单的问题,但我找不到它:
HOUR_OF_DAY 的范围是 0 到 23,还是 1 到 24?
我想要一个随机的 HOUR_OF_DAY,我需要吗:
int randomHour = (int) (Math.random()*24);
或
int randomHour = (int) (Math.random()*24+1);
最佳答案
来自 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.
如果晚上 10:04:15.250 是 HOUR_OF_DAY
22,则范围为 0
- 23
。如果是 1
到 24
,晚上 10 点。将是 23 岁。这在很多层面上都是错误的。 :-)
关于java - HOUR_OF_DAY 的范围是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23168805/