我喜欢从 Perl 5.10 开始作为标准模块包含的Time::Piece 。不幸的是,它不包括每月一周的方法。但是,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";
}
你不能比这更容易看到你的代码在做什么。