Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get "Error Parsing Time" when I use the format string "%FT%T" with Time::Piece->strptime?

Tags:

datetime

perl

I am trying to convert 2015-09-11T04:00:00 to a Time::Piece object. I tried:

my $date = "2015-09-11T04:00:00";
my $t = Time::Piece->strptime($date, '%FT%T');
print $t->strftime('%F %T');

But I get Error Parsing Time. I think it is because I am looking for %FT%T and this is causing issues because of the spacing. How would I fix this?

like image 791
Bijan Avatar asked Sep 10 '15 18:09

Bijan


1 Answers

Time::Piece seems to have some bugs in this area. In particular, it thinks that strptime %T is equivalent to %B %e, unlike what its documentation claims.

strftime %F and %T don't work for me either, but that may be because I'm on Windows.

Sticking to standard format specifications works fine, though:

my $date = "2015-09-11T04:00:00";
my $t = Time::Piece->strptime($date, '%Y-%m-%dT%H:%M:%S');
print $t->strftime('%Y-%m-%d %H:%M:%S'), "\n";
like image 191
melpomene Avatar answered Oct 02 '22 11:10

melpomene