查找Perl的天数

Fut*_*eek 0 perl time

我有两个日期格式为年 - 月 - 日时:分:秒

例如:2015-01-01 10:00:002015-01-10 11:00:00.我想计算这两天之间的天数10.

我尝试了本地时间功能,但没有工作.我需要在perl中使用这个解决方案.请帮忙.

Hun*_*len 7

Time :: Piece一直是Perl的标准模块:

use strict;
use warnings;

use feature qw(say);
use Time::Piece;

my $date1 = '2015-01-01 10:00:00';
my $date2 = '2015-01-10 11:00:00';

my $format = '%Y-%m-%d %H:%M:%S';

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

# subtraction of two Time::Piece objects produces a Time::Seconds object 
say $diff->days;
Run Code Online (Sandbox Code Playgroud)