Convert string date to Perl DateTime

datetime, perl

Solution

If you want to display milliseconds, use this format `%3N`:

my $strp = DateTime::Format::Strptime(
    pattern    => "%b %d %H:%M:%S.%3N"    # now we have the milliseconds part
)

The number jut before the `N` means the number of digits that will be displayed. The number displayed is truncated, not rounded.

Problem

I'm a newbie in Perl, so please be patient with me: I am writing a log parser and have successfully parsed "Dec 1 17:45:36.185" into it's individual units (month, day, hour, minute, seconds, milliseconds). I want to convert this to Perl's `DateTime` object. I'm having trouble with the milliseconds portion: .185. I hope to use `DateTime::Format::Strptime` like such: ``` my $strp = DateTime::Format::Strptime( pattern => "%b %d %H:%M:%S" # how do I add the milliseconds part? ) ```

Original source

Related problems