Perl strptime格式与strftime不同
发布时间:2020-12-15 23:25:46 所属栏目:大数据 来源:网络整理
导读:我正在尝试使用格式为的日期字符串: 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
我正在尝试使用格式为的日期字符串:
生成此字符串的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 Error parsing time at /usr/local/lib/perl/5.14.2/Time/Piece.pm line 469. 或者如果我试试这个: perl -MPOSIX=strftime -MTime::Piece -E 'Time::Piece->strptime(strftime(q{%F},q{%F});' 我懂了: garbage at end of string in strptime: 2013-11-15 at /usr/local/lib/perl/5.14.2/Time/Piece.pm line 469. 在男人说,%F是strptime和strftime的ISO8601日期格式. strptime向后兼容strftime吗? 解决方法
该模块使用自己的strptime实现,它不理解%F.它没有实现自己的strftime.这是一场等待发生的灾难 – 你绝对应该使用来自同一来源的strftime和strptime. Time :: Piece :: strptime看起来像是一个没有广泛可用,标准化的strptime的时代的移民.
既然strptime在POSIX中,我希望POSIX.pm可以导出它,这样你就可以使用系统的strptime了.但显然该模块也未能跟上.有一个单独的 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |