Hi Monks-

I'm parsing a logfile that gives me Timezone, Month, Day, Year, and the number of milliseconds since midnight. I would like to create a timestamp string down to the milliseconds of the form:

mm/dd/yyyy hh:mm:ss.xxx

I fancy using DateTime to help me out with this, but I'm having trouble figuring out how to generate and provide the fraction of a second to it. I am forced to use perl5.8 - any help is very much appreciated!

Thanks

-Craig

Here is my current code that does not handle fractions of a second:

use strict; use warnings; # Get Data... my ($tZone, $pMonth, $pDay, $pYear, $pStart) = qw(-04:00 05 30 2012 50 +460904); print STDERR "tZone=$tZone pMonth=$pMonth pDay=$pDay pYear=$pYear pSta +rt=$pStart\n"; use DateTime; # Start from midnight... my $dt = DateTime->new(year=>$pYear, month=>$pMonth, day=>$pDay, hour= +>00, minute=>00, second=>00, time_zone=>$tZone); # Add in milliseconds since midnight (pStart)... $dt->add(seconds=>int($pStart/1000)); my $timestamp = $dt->strftime('%D %T.%3N'); print STDERR "timestamp=$timestamp\n";

In reply to Providing Fractions of a second to DateTime? by cmv

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.