3 回答
TA贡献1875条经验 获得超5个赞
#!/usr/bin/perl
use strict;
use warnings;
use Time::Local; #自带日期模块
my $input = shift;
my ($year, $mon, $day) = $input=~/(\d{2})(\d{2})(\d{2})/;
my $today = time();
my $other_day = timelocal(0,0,0,$day,$mon-1, $year);
my $diff = $other_day - $today;
printf "It is %.2f days ", abs($diff/(60*60*24));
print $diff>0? "in the future\n" : "ago\n";
TA贡献1744条经验 获得超4个赞
模块不用另外装的。本来就有,连载入都不用啊,除非你的版本特别老?
以下是一些时间的常见用法。你自己直接用这些函数就好了,我做了简单的注解。
my $t=time; # 得到时间,不过是一串数字
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($t); #也可以用=gmtime
$year+=1900; # $year变量的意思是since 1900
my @months = qw (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); # count since 0
message("$year-$months[$mon]-$mday $hour:$min:$sec, isdst: $isdst, day: $mday"); # number of seconds since Jan 1st, 1970
- 3 回答
- 0 关注
- 461 浏览
添加回答
举报