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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |