Issue
A simple question, but I couldn't find an answer to it:
Is the range of
HOUR_OF_DAYbetween 0 and 23, or 1 and 24?
If I want a random HOUR_OF_DAY, do I need:
int randomHour = (int) (Math.random() * 24);
or
int randomHour = (int) (Math.random() * 24 + 1);
Solution
From the documentation:
Field number for get and set indicating the hour of the day.
HOUR_OF_DAYis used for the 24-hour clock. E.g., at 10:04:15.250 PM theHOUR_OF_DAYis 22.
If 10:04:15.250 PM is HOUR_OF_DAY 22, That would make the range 0 - 23. If it were 1 to 24, 10 p.m. would be 23. And that would be wrong on so many levels. :-)
Answered By - T.J. Crowder
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.