#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use Date::Simple;
use Time::Piece;
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";
$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