Time::Piece strptime 与 %X 有问题

Time::Piece strptime has trouble with %X

我正在尝试使用 perl v5.26 中的 Time::Piece->strptime() 解析以下数据:

my $str = "Mon Feb 21 02:54:49 IST 2022";
my $time_zone = substr($str, 20, 3);
my $date_time = Time::Piece->strptime($str, "%a %b %e %X $time_zone %Y");
print "Todays date/time is : $date_time";

但是,当我执行上面的代码片段时,出现以下错误:

Error parsing time at /usr/local/lib64/perl5/Time/Piece.pm line 598.

我不确定我错过了什么,任何帮助都会很有帮助。

%X 没有最后的 AM/PM 只适用于字符串的末尾。

my $str = "Mon Feb 21 IST 2022 02:54:49";
my $time_zone = substr($str, 11, 3);
warn $time_zone;
my $date_time = Time::Piece->strptime($str, "%a %b %e $time_zone %Y %X");
print "Todays date/time is : $date_time";

my $str = "Mon Feb 21 02:54:49 AM IST 2022";
my $time_zone = substr($str, 23, 3);
my $date_time = Time::Piece->strptime($str, "%a %b %e %X $time_zone %Y");
print "Todays date/time is : $date_time";

但我的测试显示此行为取决于 Perl 版本,因此可能根本不使用 %X(与 %I:%M:%S %p 相同)并切换到 %T(与 %H:%M:%S).

my $str = "Mon Feb 21 02:54:49 IST 2022";
my $time_zone = substr($str, 20, 3);
my $date_time = Time::Piece->strptime($str, "%a %b %e %T $time_zone %Y");
print "Todays date/time is : $date_time";