首页 Soft PlugIn RAN乱 Dev开发 Info资料 English WAP 留言 登陆 注册
-
Posted by Yippee | 评论(0) | 引用(0) | 阅读3289次
PERL TIME LOCALTIME 1900 1

PERL TIME LOCALTIME

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time());
$year=$year+1900; PERL 时间 日期 LOCALTIME TIME HTTP::DATE
$ss=sprintf("%04d%02d%02d%02d%02d%02d",$year,$mon+1,$mday,$hour,$min,$sec);

折腾半天,年倒是简单,看到105感觉应该加1900,可是实在是猜不透为什么月要加1

print localtime(0)."\n";

Thu Jan  1 08:00:00 1970
00700001080000

真是够无聊的

perl有两个取得时间的函数:localtime和gmtime
两个函数的用法一样,区别在于localtime为取得本地时间, gmtime格林威治时间

#!/usr/bin/perl
#get local time
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

其中: $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
               Converts a time as returned by the time function to a 9-element list with the time analyzed for
               the local time zone.  Typically used as follows:
                   #  0    1    2     3     4    5     6     7     8
                   ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
               All list elements are numeric, and come straight out of the C 鈥榮truct tm鈥?  $sec, $min, and
               $hour are the seconds, minutes, and hours of the specified time.  $mday is the day of the month,
               and $mon is the month itself, in the range 0..11 with 0 indicating January and 11 indicating
               December.  $year is the number of years since 1900.  That is, $year is 123 in year 2023.  $wday
               is the day of the week, with 0 indicating Sunday and 3 indicating Wednesday.  $yday is the day
               of the year, in the range 0..364 (or 0..365 in leap years.)  $isdst is true if the specified
               time occurs during daylight savings time, false otherwise.

               Note that the $year element is not simply the last two digits of the year.  If you assume it is,
               then you create non-Y2K-compliant programs--and you wouldn鈥檛 want to do that, would you?
               The proper way to get a complete 4-digit year is simply:         $year += 1900;

               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)").
        In scalar context, "localtime()" returns the ctime(3) value:

                   $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
               use the "gmtime" builtin. See also the "Time::Local" module (to convert the second, minutes,
               hours, ... back to the integer value returned by time()), and the POSIX module鈥檚 strftime(3) and
               mktime(3) functions.

               To get somewhat similar but locale dependent date strings, set up your locale environment vari-
               ables appropriately (please see perllocale) and try for example:

                   use POSIX qw(strftime);
                   $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
                   # or for GMT formatted appropriately for your locale:
                   $now_string = strftime "%a %b %e %H:%M:%S %Y", gmtime;

               Note that the %a and %b, the short forms of the day of the week and the month of the year, may
               not necessarily be three characters wide.


字体:

Permanant URI永久地址 http://www.shengfang.org/blog/p/PHPTIMELOCALTIME.php
Trackback URI引用地址 http://www.shengfang.org/blog/tb.php?tb_id=1133337043

2005年11月30日15:50星期三  [Dev开发] 追踪此文的RSS
提示:
此文还没有评论。

称呼:    登陆   注册
   不注册,但记住我的信息
邮件:
(非必须)
评论: [UBB代码帮助]
粗体 斜体 下划线 链接 水平线 引用



验证码: 请输入你看见的数字
关闭UBB      提交时自动将内容复制到剪贴板

公告
Fire and Motion!

统计信息
[Yippee]||[统计]||日志:1790
在线: 9||用户: 2562 [列表]
今日:1935||到访:2671434
Rss:838376||评论:1584

最新日志

最新评论

友情链接

日历

最新引用

搜索

归档

杂项
Get RSS Feed (Version 2.0)
Get Atom Feed (Version 0.3)
编码:  UTF-8