为什么我会得到“错误解析时间”当我使用格式字符串“%FT%T”与Time :: Piece-> strptime? [英] Why do I get "Error Parsing Time" when I use the format string "%FT%T" with Time::Piece->strptime?

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

问题描述

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

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?

推荐答案

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

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆