[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: [ID 20000108.003] Error in localtime(time) function
Francisco Javier <pacho@mangle.univalle.edu.co> 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) =
localtime(time);
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 (rra@stanford.edu) <URL:http://www.eyrie.org/~eagle/>
- References to:
-
Francisco Javier <pacho@mangle.univalle.edu.co>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]