strptime? I am trying to convert 2015-09-11T04...">

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

I am trying to convert 2015-09-11T04:00:00to 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 it Error Parsing Time. I think this is because I'm looking %FT%T, and this causes problems due to the interval. How can i fix this?

+4
source share
2 answers

Have you considered from time to time: Piece for something else? DateTime , for example, does what it says on tin:

use strict;
use warnings;

use DateTime::Format::Strptime;

my $date = '2015-09-11T04:00:00';
my $strp = DateTime::Format::Strptime->new(pattern => '%FT%T');
my $dt = $strp->parse_datetime($date);

print $dt->datetime;  # prints 2015-09-11T04:00:00
+1
source

Time::Piece , . , , strptime %T %B %e, , .

strftime %F %T , - , Windows.

:

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";
+6

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


All Articles