* DateTime [#w335680e]
** DateTimeオブジェクトを作る [#yfb163bc]
$dt = DateTime->from_epoch(epoch => time() );
$dt = DateTime->now();
** DateTimeオブジェクトを加算・減算する [#s40ee4d2]
去年の年を求める。
$dt = DateTime->now();
print $dt->add(years => -1)->year;
** DateTime::Durationオブジェクト(期間)を作る [#ve2ab65c]
期間を使って計算する。
$dt2007 = DateTime->new(year=>2007);
$dt2008 = DateTime->new(year=>2008);
$duration = $dt2008 $dt2007;
$dt2009 = $dt2008 + $duration;
** DateTimeオブジェクトを比較する 1[#p75b81a0]
$dt2007 = DateTime->new(year=>2007);
$dt2008 = DateTime->new(year=>2008);
print "ok" if DateTime->compare($dt2008, $dt2007) == 1;
print "ok" if DateTime->compare($dt2008, $dt2008) == 0;
print "ok" if DateTime->compare($dt2007, $dt2008) == -1;
** DateTimeオブジェクトを比較する 2[#p75b81a0]
$duration = $dt2007 - $dt2008;
$duration->is_positive; # => 0
$duration->is_negative; # => 1
$duration->is_zero; # => 0
** 参考 [#ofb27d0a]
- http://search.cpan.org/~drolsky/DateTime-0.40/lib/DateTime.pm
- http://search.cpan.org/~drolsky/DateTime-0.40/lib/DateTime/Duration.pm