DateTime::Format::*

DateTimeのオブジェクトをDateTime::Format::*でフォーマットする

use DateTime;
use DateTime::Format::W3CDTF;

my $fmt = DateTime::Format::W3CDTF->new;
my $dt = DateTime->now(time_zone => 'Asia/Tokyo');
print $fmt->format_datetime($dt); #2007-06-26T23:16:22+09:00

DateTime::Format::*の形式の文字列をDateTimeオブジェクトにする

use DateTime;
use DateTime::Format::W3CDTF;

my $fmt = DateTime::Format::W3CDTF->new;
my $time = $fmt->parse_datetime('2007-06-26T23:16:22+09:00');
print $time->ymd; #2007-06-26

formatterをDateTimeオブジェクト作る際に渡せばこれだけでフォーマットされた文字列に

my $fmt = DateTime::Format::W3CDTF->new;
my $dt =DateTime->now(
    time_zone => 'Asia/Tokyo',
    formatter => $fmt,
);

say $dt;