使用 datetime 的元素

设置单个元素:

$dt->set( year => 2016 );

设置很多元素:

$dt->set( year => 2016, 'month' => 8);

添加持续时间到 datetime

$dt->add( hour => 1, month => 2)

日期时间减法:

my $dt1 = DateTime->new(
      year      => 2016,
      month     => 8,
      day       => 20,
);

my $dt2 = DateTime->new(
      year      => 2016,
      month     => 8,
      day       => 24,
);

my $duration = $dt2->subtract_datetime($dt1);
print $duration->days

你会得到 4 天的结果