了解知识
localtime表示系统时间。
time表示从1970年开始到现在时间的总秒数。
gmtime表示标准格林威治时间。
先看三者打出来的结果:
[root@localhost test]# more an.pl
#!/usr/bin/perl
my $time=localtime;
print "localtime:",$time,"\n"; ###说明localtime(time)可以简写为localtime
my $time1=localtime(time);
print "loacaltime(time):",$time1,"\n";
my $now=time; ###展示time
print “time:”,$now,”\n”;
my $gmtime=gmtime; ###展示gmtime
print “gmtime:”,$gmtime,”\n”;
运行结果:
[root@localhost test]# ./an.pl
loacaltime: Thu Feb 4 13:12:13 2010
loacaltime(time):Thu Feb 4 13:12:13 2010
time: 1265260333
gmtime: Thu Feb 4 05:12:13 2010
[root@localhost test]#
继续下面localtime函数的使用方法:
脚本如下:
my $timestamp="1265260333"; ###取上面time函数的结果值:1265260333
my $mydate=localtime $timestamp;
print $mydate,"\n";
my($sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst)=localtime $timestamp; ###定义localtime可返回的9个时间元素
print “$sec,$min,$hour,$day,$mon,$year,$wday,$yday,$isdst”,”\n”;
my ($year,$mi,$ss)=localtime $timestamp; ###试探localtime是否有顺序。结论是:确实有顺序。
print “$hh,$mi,$ss”,”\n”;
运行结果:
Thu Feb 4 13:12:13 2010
13,12,13,4,1,110,4,34,0
13,12,13
说明:
localtime可以把字符转为时间。
localtime返回的9个元素确实有顺序,我想先返回year,也不行。
标签: perl
扩展知识