我目前正在使用下面的代码来查找昨天的日期。
有没有替代/简单的方法呢?
码
#!/usr/bin/perl
use strict;
use warnings;
use Time::Local;
my $YesterdaysDate = spGetYesterdaysDate();
print "$YesterdaysDate\n";
sub spGetYesterdaysDate {
my ($sec, $min, $hour, $mday, $mon, $year) = localtime();
my $yesterday_midday=timelocal(0,0,12,$mday,$mon,$year) - 24*60*60;
($sec, $min, $hour, $mday, $mon, $year) = localtime($yesterday_midday);
my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
my $YesterdaysDate = sprintf "%s %02d %4d", $abbr[$mon], $mday, $year+1900;
return $YesterdaysDate;
}
提前致谢!