nikmit has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to get unix time from a time string, and was (for a second) quite pleased with myself for coming up with
my $datestr = '2017-02-10 08:12:57'; my $unixtime = timelocal(reverse split /[:\s-]+/, $datestr);
But then it returns Unix time that is one month ahead of what I expected, and the reason is not obvious to me...
The docs say timelocal synopsis is
$time = timelocal( $sec, $min, $hour, $mday, $mon, $year );I checked and I am feeding it the correct data in the correct order:
my ($sec, $min, $hour, $mday, $mon, $year) = reverse split /[:\s-]+/, +$datestr; print "sec:$sec min:$min hr:$hour mday:$mday mon:$mon year:$year\n";
What am I missing?
Was missing that month range is 0-11...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: timelocal returns time one month ahead - figured it out... (strptime/strftime/Time::Piece)
by Anonymous Monk on Feb 10, 2017 at 09:59 UTC |