Search code examples
perlstrptime

Perl strptime parse millisecond


I need to parse some time string that comes in a format like ddmmyyyyhhmmssXXX. The XXX part is millisecond. In the below code Im ignoring the millisecond part. It works but I get the error:

garbage at end of string in strptime: 293 at /usr/local/lib64/perl5/Time/Piece.pm line 482.

Whats the proper format that I should use.

$time = '11032014182819802';
$format = '%d%m%Y%H%M%S';
$t = Time::Piece->strptime($time, $format);

Solution

  • Time::Piece->strptime(substr($time, 0, -3), $format);
    

    since Time::Piece does not support milliseconds.