我喜歡Time::Piece,自Perl 5.10以來,它就被包含在標準模塊中。不幸的是,它不包括月的方法。但是,Date::Handler呢。
這是一個不錯的乾淨的界面,並使其顯而易見你要找的。太糟糕了,它不是一個標準的Perl模塊,所以你必須從CPAN安裝它。
use Date::Handler;
....
my $date = Date::Handler->new($time); #Time is std Unix # of seconds since 01/01/1970
# Is it the sixth day of the week (Mon = 1) and the first week of the month?
if ($date->WeekDay == 6 and $date->WeekOfMonth == 1) {
print "It's the first Saturday of the month!\n";
}
或者......
my $date = Date::Handler->new($time);
# Is it the first Saturday of the month?
if ($date->WeekDayName eq "Saturday" and $date->WeekOfMonth == 1) {
print "It's the first Saturday of the month!\n";
}
你不能更容易地看到什麼你的代碼是不是該做的事情。
['的perldoc -f localtime'](http://search.cpan.org/perldoc?perlfunc#localtime) – mob