日付の取得方法について

#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use Date::Simple;
use Time::Piece;

# Date::Simple を使ってみる
# 今日の日付で昨日と明日の日付を取得する
my $today = Date::Simple->new();
print 'Today is ', $today, "\n";
# 昨日の日付
print 'Yesterday is ', $today->prev, "\n";
# 明日の日付
print 'Tomorrow is ', $today->next, "\n";
# 日付の計算もできる
print 'The day after tomorrow is ', $today + 2, "\n";

# ある日付の前日と翌日の日付を取得する
my $day = Date::Simple->new('2008-02-29');
print 'A day was ', $day, "\n";
# 前日の日付
print 'A day before the day was ', $day->prev, "\n";
# 翌日の日付
print 'A day after the day was ', $day->next, "\n";

# Time::Piece を使ってみる
$today = localtime;
# 初日の日付を取得する
my $first = Time::Piece->strptime($today->strftime('%Y-%m-01'), '%Y-%m-%d');
print 'The first day of this month is ', $first->date, "\n";
# 月末の日付を取得する
my $last  = Time::Piece->strptime($today->strftime('%Y-%m-' . $today->month_last_day), '%Y-%m-%d');
print 'The last day of this month is ', $last->date, "\n";
# 前月末日の日付を取得する
my $prev = Time::Piece->strptime($today->strftime('%Y-%m-01'), '%Y-%m-%d') - 1;
print 'The last day of last month was ', $prev->date, "\n";
# 翌月初日の日付を取得する
my $next = Time::Piece->strptime($today->strftime('%Y-%m-' . $today->month_last_day), '%Y-%m-%d') + 86400;
print 'The first day of next month is ', $next->date, "\n";

実行結果

% chmod u+x date.pl
% ./date.pl        
Today is 2009-01-16
Yesterday is 2009-01-15
Tomorrow is 2009-01-17
The day after tomorrow is 2009-01-18
A day was 2008-02-29
A day before the day was 2008-02-28
A day after the day was 2008-03-01
The first day of this month is 2009-01-01
The last day of this month is 2009-01-31
The last day of last month was 2008-12-31
The first day of next month is 2009-02-01