cmv has asked for the wisdom of the Perl Monks concerning the following question:
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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Providing Fractions of a second to DateTime?
by tobyink (Canon) on Jun 12, 2012 at 14:41 UTC | |
by cmv (Chaplain) on Jun 12, 2012 at 15:00 UTC | |
|
Re: Providing Fractions of a second to DateTime?
by ansh batra (Friar) on Jun 12, 2012 at 14:13 UTC | |
by cmv (Chaplain) on Jun 12, 2012 at 14:25 UTC | |
by ansh batra (Friar) on Jun 12, 2012 at 14:32 UTC | |
by tobyink (Canon) on Jun 12, 2012 at 14:35 UTC | |
by ansh batra (Friar) on Jun 12, 2012 at 14:44 UTC | |
|
Re: Providing Fractions of a second to DateTime?
by daxim (Curate) on Jun 12, 2012 at 13:55 UTC | |
by cmv (Chaplain) on Jun 12, 2012 at 14:12 UTC |