in reply to Re: String (date) to time (integer)
in thread String (date) to time (integer)
Actually not exactly:
use strict; use Time::Local; for my $date ("06/06/2009",'01/30/09') { my ($m,$d,$y) = $date =~ m|(\d+)/(\d+)/(\d+)|; my $timet = timelocal(0, 0, 0, $d, $m, $y); print "Date '$date' => $timet\n"; print "localtime($timet): ", scalar localtime $timet, "\n"; } __END__ Date '06/06/2009' => 1246831200 localtime(1246831200): Mon Jul 6 00:00:00 2009 Day '30' out of range 1..28 at .pl line 6
As the Time::Local documentation says:
The value for the day of the month is the actual day (ie 1..31), while the month is the number of months since January (0..11).
So you need to pass in $m-1 to adjust for that.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: String (date) to time (integer)
by northwestdev (Acolyte) on Jun 06, 2009 at 15:01 UTC | |
by Corion (Patriarch) on Jun 06, 2009 at 15:05 UTC |