Time::HiRes::tv_interval seems to work just fine for this.

use strict; use Time::HiRes qw|tv_interval|; use Test::More tests=> 5; is(timeDiff('01:00:00.000', '02:00:00.000'), 1*60*60, 'one hour differ +ence'); is(timeDiff('01:00:00.000', '01:01:00.000'), 1*60, 'one minute differe +nce'); is(timeDiff('01:00:00.000', '01:00:01.000'), 1, 'one second difference +'); # 45 milliseconds is xx part of a second. is(timeDiff('01:00:00.000', '01:00:00.045'), 45/1000000, 'fraction dif +ference'); my $Starttime = "05:07:53.249"; my $Finishtime = "05:07:55.401"; my $result = timeDiff($Starttime, $Finishtime); is(timeDiff($Starttime, $Finishtime), 2 + ((401-249)/1000000)); print "Difference (floating point seconds): $result\n"; sub timeDiff { my $st = shift; my $et = shift; return tv_interval( buildHRTime($st), buildHRTime($et)); } sub buildHRTime { my $string = shift; my $seconds = 0; my @c = split(/[:.]/, $string); $seconds += $c[0] * 60 * 60; # hours to seconds $seconds += $c[1] * 60; # minutes to seconds $seconds += $c[2]; # seconds return [$seconds, $c[3]]; }

"Look, Shiny Things!" is not a better business strategy than compatibility and reuse.


OSUnderdog

In reply to Re: time difference in milliseconds by osunderdog
in thread time difference in milliseconds by Anonymous Monk

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.