Created
November 15, 2013 06:53
-
-
Save iandexter/7480233 to your computer and use it in GitHub Desktop.
Convert timestamps to epoch time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Time::Local; | |
sub toepoch { | |
my $timestamp = shift; | |
my ($mon, $mday, $year, $hour, $min, $sec, $ampm) = | |
split(/[\/\s:]/, $timestamp); | |
$hour = ($ampm =~ /PM/ && $hour < 12) ? $hour+12 : $hour; | |
return timelocal($sec,$min,$hour,$mday,$mon-1,$year); | |
} | |
sub toepoch { | |
my $timestamp = shift; | |
my %months = qw( | |
jan 1 feb 2 mar 3 apr 4 may 5 jun 6 | |
jul 7 aug 8 sep 9 oct 10 nov 11 dec 12 | |
); | |
my ($weekday, $mday, $month, $year, $hour, $min, $sec, $zone) = | |
split(/[\/\s:]/, $timestamp); | |
my $mon = $months{ lc substr($month, 0, 3) }; | |
return timelocal($sec,$min,$hour,$mday,$mon-1,$year); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment