我想在Perl中做兩個日期的基本比較。當前日期時間和過去時間是正確的,但減法給出不正確的結果。差異應該是〜24小時,但它返回〜13小時。任何想法爲什麼以及如何解決它?謝謝。爲什麼我的Time :: Piece代碼給出奇怪的結果?
use Time::Piece;
my $now = Time::Piece->new;
my $then = Time::Piece->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";
Results
------
Current time: Tue Apr 15 16:13:39 2014
Past time: Mon Apr 14 16:30:20 2014
Diff in Seconds:49399
Pretty Diff:13 hours, 43 minutes, 19 seconds
優秀的,就是這樣。謝謝 – user1768233