perl how to convert a string to Datetime?

前端 未结 3 999
天涯浪人
天涯浪人 2021-02-05 10:06

I tried to convert a string to date in perl, but get error.

use strict; 
use warnings;  
use DateTime;  
use Date::Manip;

my $date = ParseDate(\"20111121\");
p         


        
3条回答
  •  遥遥无期
    2021-02-05 10:41

    DateTime doesn't parse dates. I'd go for the Time::Piece core module that gives you strptime():

    #!/usr/bin/env perl
    use strict;
    use warnings;
    use Time::Piece;
    my $t = Time::Piece->strptime("20111121", "%Y%m%d");
    print $t->strftime("%w\n");
    

提交回复
热议问题