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

前端 未结 4 1359
日久生厌
日久生厌 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 06:48

    use DateTime::Format::Strptime;
    my $strp = DateTime::Format::Strptime->new(
        pattern   => '%m/%d/%y',
        locale    => 'en_US'
    );
    my $dt = $strp->parse_datetime('4/25/10');
    print $dt->strftime('%Y-%d-%m'), "\n";
    

    Gives:

    2010-25-04
    

提交回复
热议问题