in reply to Converting string to date
One thing you should not forget, is to decrement the month value: January is month 0, December month 11. 4-digit years are fine, though you're allowed to subtract 1900.
Here's some sample code, that calculates the time value for some date, at noon, GMT:
Result:my $datestring = "2003/11/19"; # input use Time::Local; my($y, $m, $d) = $datestring =~ m<^(\d+)/(\d+)/(\d+)$> or die "Not a valid date"; my $time = timegm(0, 0, 12, $d, $m-1, $y); print "The time value is $time, for " . gmtime($time) . "\n";
The time value is 1069243200, for Wed Nov 19 12:00:00 2003
p.s. The results are limited to the date range that applies to Unix time, thus to localtime and gmtime, i.e. from 1970 to 2035, roughly; or the equivalent on your platform — on the Mac, that's from 1904 to around 2035.
|
|---|