如何计算perl中的日期差异 [英] How to calculate date difference in perl

查看:191
本文介绍了如何计算perl中的日期差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是perl脚本中的新手。我有一个要求,我需要在分钟/秒内找到两个日期的差异。

  $ date1 = Fri Aug 30 10:53:38 2013 
$ date2 = Fri Aug 30 02:12:25 2013

你能告诉我如何实现这一点,解析,计算,模块要求和所有



感谢
Goutham

解决方案

Time :: Piece 有自2007年起成为Perl的标准部分。

 #!/ usr / bin / perl 

use严格;
使用警告;
使用5.010;
使用Time :: Piece;

我的$ date1 ='Fri Aug 30 10:53:38 2013';
我的$ date2 ='Fri Aug 30 02:12:25 2013';

我的$ format ='%a%b%d%H:%M:%S%Y';

我的$ diff = Time :: Piece-> strptime($ date1,$ format)
- Time :: Piece-> strptime($ date2,$ format);

说$ diff;


I am a novice in perl scripting. I have a requirement where in I need to find the difference of two dates in the minutes/seconds

$date1 =  Fri Aug 30 10:53:38 2013
$date2 =  Fri Aug 30 02:12:25 2013

can you tell me how do we achieve this, Parsing , calculation , modules req and all

Thanks Goutham

解决方案

Time::Piece has been a standard part of Perl since 2007.

#!/usr/bin/perl

use strict;
use warnings;
use 5.010;
use Time::Piece;

my $date1 = 'Fri Aug 30 10:53:38 2013';
my $date2 = 'Fri Aug 30 02:12:25 2013';

my $format = '%a %b %d %H:%M:%S %Y';

my $diff = Time::Piece->strptime($date1, $format)
         - Time::Piece->strptime($date2, $format);

say $diff;

这篇关于如何计算perl中的日期差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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