Perl strptime format differs from strftime

I am trying to work with date strings formatted as:

YYYY-MM-DDThh: mm: ss

The strftime format for generating this line is %FT%T:

perl -MPOSIX=strftime -E 'say strftime q{%FT%T}, localtime;'

But when I try to parse this line with 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});
'

I got this error:

2013-11-15T17: 32: 58
Error parsing time at /usr/local/lib/perl/5.14.2/Time/Piece.pm line 469.

Or if I try this:

perl -MPOSIX=strftime -MTime::Piece -E 'Time::Piece->strptime(strftime(q{%F}, localtime), q{%F});'

I got it:

garbage at end of string in strptime: 2013-11-15 at /usr/local/lib/perl/5.14.2/Time/Piece.pm line 469.

The man says that %Fis the ISO8601 date format in strptime and strftime. Is strptime true backwards compatible with strftime?

+4
source share
2

strptime, %F. strftime. , - strftime strptime, . Time::Piece::strptime , strptime.

, strptime POSIX, , POSIX.pm , strptime. , -, . POSIX::strptime , C strptime . .

+6

, Time:: Piece strftime/strptime . :

my $str = '2003-03-24T13:32:44';
my $f = '%Y-%m-%dT%H:%M:%S';
my $t = Time::Piece->strptime($str, $f);

print "$t\n";
+5

All Articles