SPUG: localtime() returning hour in wrong range?

Tim Maher tim at consultix-inc.com
Sun Apr 8 10:50:45 PDT 2007


The Camel coyly avoids specifying the ranges for most of localtime's
various return values, but gives the hint that they follow (time.h's)
"struct tm", which has the hour coded as 0-23.

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?

#! /usr/bin/perl -wl
# Tim Maher, tim at TeachMePerl.com

system 'date';  # show for comparison
(undef, $minutes, $hour)=localtime;
print "\$hour/\$minutes returned by localtime(): $hour/$minutes";

|  Tim Maher, PhD  (206) 781-UNIX   http://www.consultix-inc.com    |
|  tim at ( Consultix-Inc, TeachMePerl, or TeachMeUnix ) dot Com    |
| CLASSES: 4/23: Perl+CGI; 5/7: Basic UNIX/Linux; 5/11: Perl Hashes |
| >> My "Minimal Perl" is an Amazon Best Seller; 5 star rating! <<  |
| # Download chapters, read reviews, and order at MinimalPerl.com # |

More information about the spug-list mailing list