【发布时间】:2013-11-29 00:26:12
【问题描述】:
我正在尝试使用格式如下的日期字符串:
YYYY-MM-DDThh:mm:ss
生成该字符串的strftime格式为%FT%T:
perl -MPOSIX=strftime -E 'say strftime q{%FT%T}, localtime;'
但是当我尝试用Time::Piece解析这个日期字符串时:
perl -MPOSIX=strftime -MTime::Piece -E '
say strftime q{%FT%T}, localtime;
Time::Piece->strptime( strftime(q{%FT%T}, localtime), q{%FT%T});
'
我收到了这个错误:
2013-11-15T17:32:58 在 /usr/local/lib/perl/5.14.2/Time/Piece.pm 第 469 行解析时间时出错。或者如果我试试这个:
perl -MPOSIX=strftime -MTime::Piece -E 'Time::Piece->strptime(strftime(q{%F}, localtime), q{%F});'
我知道了:
strptime 中字符串末尾的垃圾:2013-11-15 在 /usr/local/lib/perl/5.14.2/Time/Piece.pm 第 469 行。
在 man 中,%F 是 strptime 和 strftime 中的 ISO8601 日期格式。 strptime 是否向后兼容 strftime?
【问题讨论】:
-
以上所有内容都适用于我在 Scientific Linux 6.4 上的 Perl 5.10.1。
-
@ThisSuitIsBlackNot,你是幸运的:)