develooper Front page | perl.perl5.porters | Postings from October 2003

Re: [perl #24372] Errors in gmtime() and localtime()

Thread Previous
From:
Michael G Schwern
Date:
October 30, 2003 21:29
Subject:
Re: [perl #24372] Errors in gmtime() and localtime()
Message ID:
20031031052903.GC704@localhost.comcast.net
On Fri, Oct 31, 2003 at 12:40:52AM -0000, derek@dongray.fsnet.co.uk (via RT) wrote:
> At 00:35:26 31 oct 2003 GMT, the one-liner:
> 
> perl -e '@l=gmtime();for(@l){print;print qq{ }}'
> 
> produces:
> 
> 26 35 0 31 9 103 5 303 0 
> 
> I.e. the year is returned as 103 instead of 2003.
> localtime() produces the same result.

This is, alas, how localtime() and gmtime() work. :(

     $year is the number of years since 1900.  That is,
     $year is 123 in year 2023. 

This is because Perl's localtime() parrots the interface of C's localtime().
Presumably C did it that way so that it could fit the year in 8 bits (ie.
0 to 255). 


-- 
Michael G Schwern        schwern@pobox.com  http://www.pobox.com/~schwern/
Do not try comedy at home!  Milk & Cheese are advanced experts!  Attempts at
comedy can be dangerously unfunny!

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About