develooper Front page | perl.perl5.porters | Postings from January 2000

Re: [ID 20000108.003] Error in localtime(time) function

Thread Previous | Thread Next
Russ Allbery
January 8, 2000 18:12
Re: [ID 20000108.003] Error in localtime(time) function
Message ID:
Francisco Javier <> writes:

> The localtime(time) function returns `100' as the year, that's wrong.

I'm sorry to disagree, but no, it's not.  It's exactly what the
documentation of localtime has been saying it would return since
essentially the beginning of Perl.

windlord:~> perldoc -f localtime
    localtime EXPR
            Converts a time as returned by the time function to a 9-element
            array with the time analyzed for the local time zone. Typically
            used as follows:

                #  0    1    2     3     4    5     6     7     8
                ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =

            All array elements are numeric, and come straight out of a struct
            tm. In particular this means that `$mon' has the range `0..11' and
            `$wday' has the range `0..6' with sunday as day `0'. Also, `$year'
            is the number of years since 1900, that is, `$year' is `123' in
            year 2023, and not simply the last two digits of the year.

It's somewhat non-intuitive, I realize, but not incorrect.  In this
behavior, Perl is following the behavior of the underlying C library and
the format of a struct tm.

Russ Allbery (         <URL:>

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About