print time,"\n";
localtime在列表上下文返回的是各個時間部分,在標量上下文返回的是一個本地格式的時間值。app
[root@xuexi perlapp]# perl -e '$a=localtime;print $a,"\n";' Sat Sep 8 09:03:56 2018
如下是localtime在列表上下文返回的各個時間部分:操作系統
# 0 1 2 3 4 5 6 7 8 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
其中:unix
例如:code
use 5.010; @time=localtime; say qq(second : $time[0]); say qq(minute : $time[1]); say qq(hour : $time[2]); say qq(mon_day : $time[3]); say qq(month : $time[4]); say qq(year : $time[5]); say qq(week_day: $time[6]); say qq(year_day: $time[7]); say qq(isdst : $time[8]);
輸出結果爲:perl
second : 42 minute : 10 hour : 9 mon_day : 8 month : 8 year : 118 week_day: 6 year_day: 250 isdst : 0
之因此用0表示1月份,11表示12月份,是爲了讓月份數值和偏移對應。例如,偏移0位表示1月。im
my @month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); print "$month[$mon]"