日期转换

vkr*_*ris 2 perl date

在perl中,我如何转换日期

Thu Mar 06 02:59:39 +0000 2008
Run Code Online (Sandbox Code Playgroud)

2008-03-06T02:59:39Z
Run Code Online (Sandbox Code Playgroud)

尝试HTTP :: Date,如果问题在字符串中没有+0000,它可以工作:(

Chr*_*ley 6

DateTime :: Format :: Strptime将执行此转换.

#!/usr/bin/perl
use strict;
use warnings;
use 5.012;
use DateTime::Format::Strptime;

my $date = 'Thu Mar 06 02:59:39 +0000 2008 ';

my( @strp ) = (
    DateTime::Format::Strptime->new( pattern => "%a %b %d %T %z %Y", ),
    DateTime::Format::Strptime->new( pattern => "%FY%T%Z", )
);

my $dt = $strp[0]->parse_datetime( $date );

print $strp[1]->format_datetime( $dt );
Run Code Online (Sandbox Code Playgroud)

打印2008-03-06T02:59:39UTC

克里斯