(perl version 5.8.7)
I have two date strings and and try to calculate date and time difference between two dates and times.
But the difference looks incorrect, could you help me to get the correct value?
notBefore=Nov 23 22:31:12 2019 GMT
notAfter=Mar 19 06:52:23 2020 GMT
#!/usr/bin/perl use Time::Local; # FILE READ IN $log_file = './raw.txt'; open(FH, '<', $log_file) or die $!; while (<FH>) { if(m/START/) {chomp; $sdname = $_;} if(m/notBefore/) { chomp; ($notB1, $notB2) = split('=', $_); $notB2 =~ tr/:/ /; my($mon,$mday,$hour,$minute,$sec,$year)=split(/ /,$notB2); #print $mon, $mday, $hour, $minute, $sec, $year; $time_1 = timelocal($sec,$minute,$hour,$mday,$mon,$year); } if(m/notAfter/) { chomp; ($notA1, $notA2) = split('=', $_); $notA2 =~ tr/:/ /; my($mon,$mday,$hour,$minute,$sec,$year)=split(/ /,$notA2); $time_2 = timelocal($sec,$minute,$hour,$mday,$mon,$year); } if(m/END/) {printf("%s %s %s\n", $sdname, $notB2, $notA2); print $time_2,"\n",$time_1, "\n"; $diff_time = $time_2 - $time_1; $diff_time1 = ($diff_time/86400); print "diff_time :$diff_time:$diff_time1:\n"; } }
===output=====
SD0101START Nov 23 22 31 12 2019 GMT Mar 19 06 52 23 2020 GMT
1579384343
1548250272
diff_time :31134071:360.348043981481:
========rax.txt===========
SD0101START
notBefore=Nov 23 22:31:12 2019 GMT
notAfter=Mar 19 06:52:23 2020 GMT
SD0101END
SD0201START
notBefore=Nov 24 11:11:11 2019 GMT
notAfter=Mar 19 06:52:23 2020 GMT
SD0201END
In reply to date and time difference by invisiblehand
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |