How can I change the date formats in Perl?

前端 未结 5 1806
生来不讨喜
生来不讨喜 2020-12-07 02:16

I just want to convert the dates from 20111230 format to 30-dec-2011.

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 02:36

    A quick solution.

    my $date = '20111230';
    my @months = (
        'Jan','Feb','Mar','Apr',
        'May','Jun','Jul','Aug','Sep',
        'Oct','Nov','Dec'
    );
    
    if($date =~ m/^(\d{4})(\d{2})(\d{2})$/){
            print $3 . '-' . $months[$2-1] . '-' . $1;
    }
    

提交回复
热议问题