Compare date time zone with time() in perl -


i trying compare file creation time in format: 08-07-2016 08:16:26 gmt current time using time() in perl. since time() returns epoch time, not sure how find time difference between these 2 different time formats.

i tried below , obvious reasons, error saying: "argument 08-07-2016 08:16:26 gmt" isn't numeric in subtraction".

my $current_time = time(); $time_diff = $creation_time - $current_time; if ($time_diff > 10) {                  #compare if difference greater 10hours     # something... } 

some of questions have:

  1. since want compare hour difference, how can extract hours both these time formats?
  2. i unsure if comparison of $time_diff > 10 right. how represent 10hours? 10*60?

or there way @ least convert given time format epoch using datetime or time::local?

how can pass a date parameter datetime constructor?

my $dt1 = datetime-> new (                  year =>'1998',                  month =>'4',                  day   =>'4',                  hour  =>'21',                  time_zone =>'local'                  ); 

instead can like

my $date = '08-07-2016 08:16:26 gmt'; $dt1 = datetime->new($date);  # how can pass parameter constructor print dumper($dt1->epoch); 

thanks in advance help.

time::piece has been standard part of perl since 2007.

#!/usr/bin/perl  use strict; use warnings; use 5.010;  use time::piece; use time::seconds;  $creation_string = '08-07-2016 08:16:26 gmt';  $creation_time = time::piece->strptime($creation_string, '%d-%m-%y %h:%m:%s %z'); $current_time = gmtime;  $diff = $current_time - $creation_time;  $diff; # difference in seconds $diff->pretty; 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -