使用Perl模块轻松查找昨天的日期

时间:2014-12-11 07:53:22

标签: perl perl-module

我目前正在使用下面的代码来查找昨天的日期。

有没有替代/简单的方法呢?

#!/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;
}

提前致谢!

0 个答案:

没有答案