my $t = Time::Piece->strptime("Sunday 3rd Nov, 1943",
"%A %drd %b, %Y");
print $t->strftime("%a, %d %b %Y");
####
Wed, 03 Nov 1943
##
##
#!/usr/bin/perl
# vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
use strict;
use warnings;
use Carp;
use Time::Piece;
$SIG{__WARN__} = sub { Carp::cluck @_; };
$SIG{__DIE__} = sub { Carp::confess @_; };
$| = 1;
my $t = localtime;
my $pattern = "%a, %d %b %Y %T %Z";
my $str = $t->strftime( $pattern );
print "Time is:\n", $str, "\n";
# Format: Wed, 13 Jan 2021 17:22:23 CST
my $u = Time::Piece->strptime( $str, $pattern, );
print "Time is:\n", $u->strftime( $pattern ), "\n";
##
##
$ perl ./tp_test.pl
Time is:
Wed, 13 Jan 2021 22:21:49 CST
Error parsing time at /usr/lib64/perl5/Time/Piece.pm line 597.
at ./tp_test.pl line 11.
main::__ANON__("Error parsing time at
/usr/lib64/perl5/Time/Piece.pm line 597.\x{a}") called
at /usr/lib64/perl5/Time/Piece.pm line 597
Time::Piece::strptime("Time::Piece",
"Wed, 13 Jan 2021 22:21:49 CST", "%a, %d %b %Y %T %Z")
called at ./tp_test.pl line 23
$
##
##
$ perl ./tp_test.pl
Time is:
Wed, 13 Jan 2021 22:21:49 CST
Time is:
Wed, 13 Jan 2021 22:21:49 CST
$