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?
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";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With