如何使用 Perl 获得两个时间戳的差异? [英] How can I get the difference of two timestamps using Perl?

查看:27
本文介绍了如何使用 Perl 获得两个时间戳的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我基于一个问题..我有两个具有相同格式的时间戳,例如(2010 年 12 月 14 日星期二 18:23:19 和 2010 年 12 月 14 日星期二 17:23:19).我怎样才能以小时为单位获得两个时间戳的差异.请帮帮我

Here i based one problem.. i have two timestamps with same format like (Tue Dec 14 18:23:19 2010 & Tue Dec 14 17:23:19 2010). how can i get the difference of two timestamps in hours. please help me

推荐答案

use Date::Parse;


my $t1 = 'Tue Dec 14 17:23:19 2010';
my $t2 = 'Tue Dec 14 18:23:19 2010';

my $s1 = str2time( $t1 );
my $s2 = str2time( $t2 );

print $s2 - $s1, " seconds\n";

这篇关于如何使用 Perl 获得两个时间戳的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆