Created
November 28, 2011 08:34
-
-
Save numberwhun/1399627 to your computer and use it in GitHub Desktop.
Convert Date-Time to Epoch Seconds
This file contains 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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Time::Local; | |
############################################################## | |
# Use this snippet carefully. The date is in a specific | |
# format, but you can code to pull appart another date format | |
# if you wish. | |
############################################################## | |
############################################################## | |
# This date in epoch is 1175191200 | |
############################################################## | |
my $date= "2007-03-29 14:00:00"; | |
my ($year, $month, $day, $hour, $min, $sec) = split /\W+/, $date; | |
############################################################## | |
# The value of month needs to be the month's number | |
# (ie: August is 8)minus 1 due to the fact that Perl counts | |
# starting at 0, not 1 | |
############################################################## | |
$month = $month - 1; | |
############################################################## | |
# Year is an offset from 1900. So, you take the present | |
# year and subtract 1900 to get the offset of 107. | |
############################################################## | |
$year = $year - 1900; # This will give you the correct value of 107. | |
my $time = timelocal($sec,$min,$hour,$day,$month,$year); | |
print("$time \n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment