我已經在StackOverflow中看到了關於如何計算兩個日期之間的時間差異的一些答案。但是沒有答案在PHP中使用DateTime obejct或Interval Object。我從PHP手冊網站獲得了以下代碼片段:http://www.php.net/manual/en/dateinterval.format.php。使用PHP間隔對象計算天差異?
<?php
$january = new DateTime('2010-01-01');
$february = new DateTime('2010-02-01');
$interval = $february->diff($january);
// %a will output the total number of days.
echo $interval->format('%a total days')."\n";
// While %d will only output the number of days not already covered by the
// month.
echo $interval->format('%m month, %d days');
?>
但問題是,總天數等於6015天,應該只有31天。我試圖訪問Interval對象中的實例變量days。它也顯示6015天。但月份和日期間隔的情況是正確的。有人能告訴我爲什麼嗎?
而我想用這些對象來計算時間的差異!
非常感謝
UPDATE:
我覺得這只是我的PHP設置有問題
這是與Windows上的PHP相關的問題。 http://stackoverflow.com/questions/2519261/how-to-get-aggregate-days-from-phps-datetimediff – 2011-01-12 20:34:48