Re: How to convert timestamp to epoch?



Oops, actually this is the working version:

sub timestamp_to_epoch {
my ($ts) = @_;
my %month = (
'JAN' => 0, 'FEB' => 1, 'MAR' => 2, 'APR' => 3,
'MAY' => 4, 'JUN' => 5, 'JUL' => 6, 'AUG' => 7,
'SEP' => 8, 'OCT' => 9, 'NOV' => 10, 'DEC' => 11);
my $regex = '^(\d{1,2})-(\w{1,3})-(\d{1,2}) ';
$regex .= '(\d{1,2})\.(\d{1,2})\.(\d{1,2})';
$regex .= '\.\d+ ([AP])M$';
if ($ts =~ m{$regex}i) {
my ($dd, $mo, $yy, $hh, $mm, $ss, $ap) =
($1, $2, $3, $4, $5, $6, $7);
$yy += 2000; $mo = $month{uc($mo)};
if (uc($ap) eq 'P' && $hh != 12) {
$hh += 12;
}
elsif (uc($ap) eq 'A' && $hh == 12) {
$hh -= 12;
}
return timelocal($ss, $mm, $hh, $dd, $mo, $yy);
}
else { return 0; }
}

.