Perl Time Stamp Compare

Work in Progress…

The script below is a work in progress for another project.  I figured I would go ahead and post it in the event that some part of it is helpful to someone.  The perl script below takes a custom date/time and converts it to epoch, and then it is subtracted from the current epoch time.

use Time::Local;
use Time::Piece;
use List::MoreUtils qw(firstidx);

my $currentEpoch = localtime(time) -> epoch;
my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec);
my $mMonth = "Jun";
my $monthInx = firstidx { $_ eq $mMonth } @months;
my $mYr = "2017";
my $mDay = "1";
my $mHr = "8";
my $mMin = "33";
my $mSec = "0";
my $timeVar = timelocal($mSec,$mMin,$mHr,$mDay,$monthInx,$mYr);
my $convertedEpoch = localtime($timeVar) -> epoch;
print $currentEpoch - $convertedEpoch;
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s