1
我在兩個日期之間的差異計算有麻煩。Perl DateTime持續時間格式不顯示年份
my $todayDate = DateTime->now;
my @updateDateFields = split /\//, $proteinObj->{lastUpdate}; #yyyy/mm/dd
my $updateDateTime = DateTime->new(
year => @updateDateFields[0],
month=> @updateDateFields[1],
day=> @updateDateFields[2]
);
my $daysSinceLastUpdate = $todayDate - $updateDateTime;
my $dfd = DateTime::Format::Duration->new(pattern => '%Y years, %m months, %e days');
print "Last update was: ". $dfd->format_duration($daysSinceLastUpdate). " ago.\n";
和輸出是這樣的:
最後更新日期:2015/01/13最後更新時間爲:0年22月,0 天前。
它沒有顯示1年,10個月,0天前。
順便說一句,'使用warnings'告訴我,'標量值@updateDateFields [0]更好地寫成$ updateDateFields [0]'等 – choroba
哇,你是對的,但它加載我的應用程序如此之快,我無法趕上它,非常感謝您的反饋 – dmance
我建議你看看[*當有人回答我的問題,我應該怎麼做?*] (http://stackoverflow.com/help/someone-answers) – Borodin