Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@numberwhun
Created November 28, 2011 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save numberwhun/1399627 to your computer and use it in GitHub Desktop.
Save numberwhun/1399627 to your computer and use it in GitHub Desktop.
Convert Date-Time to Epoch Seconds
#!/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