本文介绍了为什么我会得到“错误解析时间”当我使用格式字符串“%FT%T”与Time :: Piece-> strptime?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在尝试将 2015-09-11T04:00:00 转换为对象。我试过:

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');

但是我得到解析时间错误。我认为这是因为我正在寻找%FT%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?

推荐答案

例如,在锡上说明了什么:

Have you considered ditching Time::Piece for something else? DateTime, for example, does what it says on the 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

这篇关于为什么我会得到“错误解析时间”当我使用格式字符串“%FT%T”与Time :: Piece-> strptime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-09 01:55