How to parse microseconds with Time :: Piece strptime?

I have a timestamp that looks like 25-OCT-10 04.11.00.000000 AM. I am trying to convert this to a time format using

Time::Piece->strptime("25-OCT-10 04.11.00.000000 AM","%d-%b-%y %I.%M.%S.%6N %p")

but he continues to throw errors. I tried %OS, %SZ. They do not seem to work. Can someone tell me what I'm doing wrong?

+3
source share
2 answers

Time :: Piece does not support secondary times. Try DateTime instead of e.g. DateTime :: Format :: Strptime

use DateTime::Format::Strptime;

my $parser = DateTime::Format::Strptime->new(
  pattern => '%d-%b-%y %I.%M.%S.%6N %p',
);

my $dt = $parser->parse_datetime("25-OCT-10 04.11.00.000000 AM");
+11
source

strptime . strptime , , - , N Time::Piece strptime. , .000000 , ..."%I.%M.%S.000000 %p", strptime .

DateTime:: Format:: CLDR? "dd-MMM-yy hh.mm.ss.SSSSSS a", , .

use DateTime::Format::CLDR;
my $parser = DateTime::Format::CLDR->new(
    pattern => "dd-MMM-yy hh.mm.ss.SSSSSS a",
    locale => "en_US",
);
my $dt = $parser->parse_datetime("25-OCT-10 04.11.00.000100 AM");

say $dt->iso8601; # 2010-01-25T04:11:00

: , , - "", "OCT". ​​ :)

: DateTime:: Format:: CLDR 1.11 .

+5

Source: https://habr.com/ru/post/1771240/


All Articles