免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 7420 | 回复: 7
打印 上一主题 下一主题

请教:perl中的时间函数 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-01-10 14:38 |只看该作者 |倒序浏览
比如我现在有一个时间"2005-10-21 10:00:00" 我要获取相对该时间7天前(当然也可能是其它间隔单位)时间,有什么函数可以实现?
谢谢

另外,localetime可以将time时间转换位年月日,什么函数可以进行相反的转化(类似C语言中的mktime函数功能)吗?

多谢

[ 本帖最后由 tramplzh 于 2006-1-10 15:04 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2006-01-10 15:40 |只看该作者
沙发,我也要处理这个问题

论坛徽章:
0
3 [报告]
发表于 2006-01-10 16:51 |只看该作者
Time::Local
可以试试。
或者什么 Date::Simple 之类的。

论坛徽章:
0
4 [报告]
发表于 2006-01-10 16:59 |只看该作者
use POSIX qw(strftime);
use Time::Local;
#timelocal($sec,$min,$hour,$day,$mon,$year);
sub main {
        my ($date_hd);

        my $tims = timelocal("00","00","16","10","01","2006";
        $date_hd = strftime "%Y-%m-%d %H:%M:%S", localtime($tims);
        my $ses = localtime($tims);
        printf"ses=$ses,$date_hd\n";
        $date_hd = strftime "%Y-%m-%d %H:%M:%S", localtime(time);
        my $ses = localtime(time);
        printf"ses=$ses,$date_hd\n";

}

main();


转换过来后,月份加1了,这是为什么呢

论坛徽章:
0
5 [报告]
发表于 2006-01-10 17:00 |只看该作者
输出:
ses=Fri Feb 10 16:00:00 2006,2006-02-10 16:00:00
ses=Tue Jan 10 16:57:29 2006,2006-01-10 16:57:29

论坛徽章:
0
6 [报告]
发表于 2006-01-11 00:02 |只看该作者
为什么没人回复呢

论坛徽章:
0
7 [报告]
发表于 2006-01-11 08:39 |只看该作者
这段引用自cpan的Time::Local文档,你好好看看就知道为什么了!
It is worth drawing particular attention to the expected ranges for the values provided. The value for the day of the month is the actual day (ie 1..31), while the month is the number of months since January (0..11). This is consistent with the values returned from localtime() and gmtime().

论坛徽章:
0
8 [报告]
发表于 2006-01-11 10:59 |只看该作者
谢谢
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP