in reply to unix timestamp
Time::Local requires a little more work on your part, because you have to split your date string up into its components in order to use the module's "timelocal" function:
When I ran that, I got:use strict; use Time::Local; my $time_str = "2004-06-14 13:34:54"; my ($yr, $mo, $dy, $hr, $mi, $sc) = split( /\D+/, $time_str ); $mo--; # January is supposed to be "month 0" my $time_unx = timelocal( $sc, $mi, $hr, $dy, $mo, $yr ); # the function "does the right thing" given a 4-digit year # (check the Time::Local man page for more details on that) # prove that it works: print "$time_str = $time_unx (" . scalar( localtime $time_unx ) . ")\n +";
2004-06-14 13:34:54 = 1087234494 (Mon Jun 14 13:34:54 2004)
|
|---|