Yes, it's with localtime
use 5.10.1; use strict; use Time::Local; use Time::localtime; use IO::File; my $ti = localtime; my $tf; my ($logFile, $logFileH); my $basePath = "c:\\las\\dump"; my $processName = "dummy process"; my $startState = "enabled"; my $deaths = 4; my $diff; my $processNameOut; my $startStateOut; my $deathsOut; my $deathFile = "$basePath\\itrsDeaths.dat"; my $deathFileH = new IO::File(">$deathFile") or logit("Can't open fi +le: $deathFile for output.\n"); printf $deathFileH ("%-35s%-9s %-5d %s\n", $processName, $startState +, $deaths,$ti); if ( -f "$deathFile") { open(INIFILE,'<',"$deathFile") or logit( "Could not open death fil +e $deathFile: $!"); my @records = <INIFILE>; foreach my $record (@records) { my ($processNameOut, $startStateOut, $deathsOut, $ti) = $record +=~ /(\S+)\s+(\S+)\s+(\S+)\s+(\S+)?/; } close INIFILE; } else { open(INIFILE,'>',"$deathFile") or logit( "Could not create death f +ile $deathFile: $!"); close INIFILE; } sleep(2); $tf = localtime; $diff = getTimeDifferenceInSeconds($ti,$tf); say "The time difference in seconds is $diff"; sub getTimeDifferenceInSeconds { my ($t1,$t2) = @_; my $sec1 = $t1->sec; my $sec2 = $t2->sec; my $min1 = $t1->min; my $min2 = $t2->min; my $hour1 = $t1->hour; my $hour2 = $t2->hour; my $mday1 = $t1->mday; my $mday2 = $t2->mday; my $month1 = $t1->mon; my $month2 = $t2->mon; my $year1 = $t1->year; my $year2 = $t2->year; my $diff; my $es1 = timegm($sec1,$min1,$hour1,$mday1,$month1-1,$year1); my $es2 = timegm($sec2,$min2,$hour2,$mday2,$month2-1,$year2); $diff = $es2-$es1; return $diff; } sub logit { print @_; # print $logFileH @_ if ($ENV{ENABLE_ITRS_LOGGING}); }

In reply to Re^2: Converting a date to a string and back by JonesyJones
in thread Converting a date to a string and back by JonesyJones

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.