SPUG: localtime() returning hour in wrong range?
Jim Ludwig
jsl at blarg.net
Sun Apr 8 13:23:42 PDT 2007
Tim Maher wrote:
>> So why does the following program display a
>> localtime-derived hour value that /matches/ the
>> one returned by the Linux date command, rather
>> than a value that's less by one? E.g., if date
>> says it's 11 AM, shouldn't $hour be 10, not 11?
>> Am I overlooking something?
I think it is possible you're overlooking
something. Perhaps what you're overlooking was
*hinted* by Eric Wilhelm, who said:
>> Add coffee, check back at 24:01.
The 24-hour clock, or military time, begins at
0:00, which a sergeant might say as "zero hundred
hours". There is no such time as 24:01, but
rather 00:01.
Whereas the sergeant would say "zero hundred
hours", the civilian would say "twelve o'clock".
By the time 1 o'clock rolls around, both the
civilian and the sergeant are in sync.
I just ran your program on my command-line, and
its output looks correct:
--------------------------------------------------
Sun 13:20:58 {prague:[~]} which perl
/usr/bin/perl
Sun 13:20:59 {prague:[~]}
Sun 13:21:01 {prague:[~]} echo ; perl -wle 'system "date";(undef, $minutes, $hour)=localtime;print "\$hour/\$minutes returned by localtime(): $hour/$minutes";' ; echo
Sun Apr 8 13:21:10 PDT 2007
$hour/$minutes returned by localtime(): 13/21
Sun 13:21:10 {prague:[~]}
--------------------------------------------------
I hope *I*'m not missing something in your
question and that this all makes sense.
Cheers,
jim
More information about the spug-list
mailing list