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)