Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

timelocal returns time one month ahead - figured it out... sry

by nikmit (Sexton)
on Feb 10, 2017 at 09:44 UTC ( [id://1181642]=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1181642]
Approved by GotToBTru
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-18 20:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found