As DeVadder has already pointed out, this is because Time::Piece uses UTC for parsed time by default.
Assuming you want everything done using localtime , you really can encourage the parsed time to inherit your timezone from local: / p>
use Time::Piece; use strict; use warnings; my $now = Time::Piece->new; my $then = localtime->strptime("2014-04-14 16:30:20", "%Y-%m-%d %H:%M:%S"); my $diff = $now - $then; print "Current time: $now\n"; print "Past time: $then\n"; print "Diff in Seconds:", $diff, "\n"; print "Pretty Diff:", $diff->pretty, "\n";
Outputs:
Current time: Tue Apr 15 17:12:08 2014 Past time: Mon Apr 14 16:30:20 2014 Diff in Seconds:88908 Pretty Diff:1 days, 0 hours, 41 minutes, 48 seconds
source share