How to display 4/25/10 to 2010-25-04?

前端 未结 4 1362
日久生厌
日久生厌 2021-01-24 06:37
my$str= \'4/25/10\';
my$sr = join(\' \',split (/\\//,$str));
#my$s = sprintf \'%3$d %2$d %1$d\',$srt;
print$sr,\"\\n\";

output:

<
4条回答
  •  悲哀的现实
    2021-01-24 07:01

    No need to do to DateTime for this. Time::Piece has been included with the Perl core distribution for years.

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    use 5.010;
    
    use Time::Piece;
    
    my $date = '4/25/10';
    
    my $date_tp = Time::Piece->strptime($date, '%m/%d/%y');
    
    say $date_tp->strftime('%Y-%m-%d');
    

提交回复
热议问题