time 函数返回 UNIX 时间,格式如:1318301827 。
gmtime 函数返回的是世界标准时间(UTC,加上时间差后记得本地时间 localtime ),函数的返回值是一个字符串,如:Tue Oct 11 02:57:07 2011 。
localtime 返回本地时间,如果不加参数的话,返回的也是个字符串:Tue Oct 11 10:57:07 2011 。
localtime 可以后接参数,参数就是 time 函数返回的时间格式,这样一来,可以取得多个时间单位,比如年,月,日,秒,星期 等,如:
[Perl] 纯文本查看 复制代码 #!/usr/bin/perl
use 5.010;
my $now = time;
my $gnow = gmtime;
my $lnow = localtime;
my ($sec, $min, $hour, $day, $mon, $year, $wday, $yday, $isdst) = localtime $now;
say "$now";
say "$gnow";
say "$lnow";
say "second:$sec";
say "minute:$min";
say "hour:$hour";
say "day:$day";
say "mon:$mon";
say "year:$year";
say "wday:$wday";
say "yday:$yday";
say "isdst:$isdst";
运行输出:# ./time.pl
1318301827
Tue Oct 11 02:57:07 2011
Tue Oct 11 10:57:07 2011
second:7
minute:57
hour:10
day:11
mon:9
year:111
wday:2
yday:283
isdst:0 注意,上面的月份值的范围是 0-11 ,所以显示月份值为 9 时实际是在 10 月。
后面的 year 的值为 111,这个值要加上 1900 后方能得到当前的年份。
wday 表示今天是星期几。
yday 表示今年里到今天为止,一共过去了几天。
isdst 这是判断是否用的夏令时,dst 即为 daylight saving time 的缩写。 |