免费注册 查看新帖 |

Chinaunix

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

大家来看看能不能把时间转成整数 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-03-31 16:39 |只看该作者 |倒序浏览
use POSIX qw(strftime);

@time_=qw(1330566649 1330533577);

while(<@time_>)
{
$_=~/\d\d\d\d\d\d\d\d\d\d/;
print strftime("%m/%d/%Y        %H:%M:%S",localtime($&-8*60*60))."\n";
}

输出结果:
          03/01/2012      01:50:49
              02/29/2012      16:39:37


我现在想把:         
          03/01/2012      01:50:49
              02/29/2012      16:39:37
再变成:1330566649
           1330533577
不知道哪个函数能实现?

论坛徽章:
0
2 [报告]
发表于 2012-03-31 16:53 |只看该作者
Time::Local这个模块提供的函数timelocal可以把时间转成整数

论坛徽章:
0
3 [报告]
发表于 2012-04-01 11:15 |只看该作者
试下mktime

论坛徽章:
0
4 [报告]
发表于 2012-04-01 11:34 |只看该作者
3.2.1. ProblemYou want to convert a date, a time, or both with distinct values for day, month, year, etc. to Epoch seconds.

3.2.2. SolutionUse the timelocal or timegm functions in the standard Time::Local module, depending on whether the date and time is in the current time zone or in UTC.
use Time::Local;$TIME = timelocal($sec, $min, $hours, $mday, $mon, $year);$TIME = timegm($sec, $min, $hours, $mday, $mon, $year);

回复 1# wbc1223


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP