The timestamp format is as follows:
20080317 130146543
20080317 130156581
So the difference here is 38 msec.
Thanks !
R C
Just construct DateTime objects and subtract:
my $dt1 = DateTime->new(
year => 2008,
month => 03,
day => 17,
hour => 13,
minute => 01,
second => 46,
nanosecond => 543 * 1000000,
);
my $dt2 = DateTime->new(
year => 2008,
month => 03,
day => 17,
hour => 13,
minute => 01,
second => 56,
nanosecond => 581 * 1000000,
);
my $duration = $dt2 - $dt1;
print $duration->in_units('days', 'hours', 'seconds', 'nanoseconds'),
"\n";
/sandy
http://myperlquiz.com/
> nanosecond => 543 * 1000000,
Sorry, too many zeros, but you got an idea
/sandy
http://myperlquiz.com/
Most Perl programmers can tell you about a whole bunch of modules that
can help you do that.
> The timestamp format is as follows:
> 20080317 130146543
> 20080317 130156581
I for one would make use of the most(?) useful date/time module Time::Local.
use Time::Local;
sub timediff {
my @t;
foreach ( @_ ) {
my ($y, $mo, $d, $h, $min, $s, $ms) =
/^(\d{4})(\d{2})(\d{2})\s+(\d{2})(\d{2})(\d{2})(\d{3})$/
or die "Failed to parse timestamp '$_'";
push @t, timelocal($s, $min, $h, $d, $mo-1, $y) + $ms/1000;
}
sprintf '%.3f', $t[1]-$t[0];
}
my $ts1 = '20080317 130146543';
my $ts2 = '20080317 130156581';
print "ts1: $ts1\n",
"ts2: $ts2\n",
'time diff: ', timediff($ts1, $ts2), " seconds\n";
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl