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

前端 未结 4 1357
日久生厌
日久生厌 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:46

    Well, a braindead solution might be:

    my @date = split( /\//,$str)
    printf("%04d-%02d-%02d", $date[2] + 2000, $date[1], $date[0]);
    

    You could write something a little more self-documenting by highlighting what you expect to be year, month and day like so:

    my ($day, $month, $year) = split /\//, $str;
    printf("%04d-%02d-%02d", $year + 2000, $month, $day);
    

提交回复
热议问题