PERL TIME LOCALTIME ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time()); 折腾半天,年倒是简单,看到105感觉应该加1900,可是实在是猜不透为什么月要加1 print localtime(0)."\n"; Thu Jan 1 08:00:00 1970 真是够无聊的 perl有两个取得时间的函数:localtime和gmtime #!/usr/bin/perl 其中: $sec代表秒数[0,59] $min代表分数[0,59] $hour代表小时数[0,23] $mday代表是在这个月的第几天[1,31] $mon代表月数[0,11],要将$mon加1之后,才能符合实际情况。$year从1990年算起的年数 $wday从星期六算起,代表是在这周中的第几天[0-6] $yday从一月一日算起,代表是在这年中的第几天[0,365] $isdst只是一个flag 知道这些变量之后,就可以在CGI应用程序中拿来应用了。此外,也可以用下面这一行指令在UNIX系统下取得系统的时间。为了避免错误发生,最好用绝对路径的方法来取得系统时间,如果绝对路径不清楚的话可以用”which data”这个指令来得知。最后要提字符的话,就不能正确执行系统的程序了。 $data=’/usr/bin/data’; 而在perl5版本中,也可以用下面这一行指令来取得系统时间。 $data=localtime(time); localtime EXPR Note that the $year element is not simply the last two digits of the year. If you assume it is, And to get the last two digits of the year (e.g., 鈥?1鈥?in 2001) do: $year = sprintf("%02d", $year % 100); If EXPR is omitted, "localtime()" uses the current time ("localtime(time)"). $now_string = localtime; # e.g., "Thu Oct 13 04:54:34 1994" This scalar value is not locale dependent but is a Perl builtin. For GMT instead of local time To get somewhat similar but locale dependent date strings, set up your locale environment vari- use POSIX qw(strftime); Note that the %a and %b, the short forms of the day of the week and the month of the year, may 字体:大 中 小 |
![]() | 永久地址 http://www.shengfang.org/blog/p/PHPTIMELOCALTIME.php |
![]() | 引用地址 http://www.shengfang.org/blog/tb.php?tb_id=1133337043 |
2005年11月30日15:50星期三 [Dev开发]





