雖然用PHP玩,我strucked這個:PHP:奇怪DateInterval長度計算
<?php
$FebruaryTheFirst = \DateTime::createFromFormat('Y-m-d H:i:s', '2001-02-01 00:00:00');
$MarchTheSecond = \DateTime::createFromFormat('Y-m-d H:i:s', '2001-03-01 00:00:00');
$interval = $FebruaryTheFirst->diff($MarchTheSecond);
echo $interval->m.PHP_EOL; // Outputs 0. WTF?
$FebruaryTheFirstbis = \DateTime::createFromFormat('Y-m-d', '2001-02-01');
$MarchTheSecondbis = \DateTime::createFromFormat('Y-m-d', '2001-03-01');
$interval2 = $FebruaryTheFirstbis->diff($MarchTheSecondbis);
echo $interval2->m.PHP_EOL; // Outputs 1. WTF?
$FebruaryTheFirstter = \DateTime::createFromFormat('Y-m-d H:i:s', '2001-02-01 00:01:00');
$MarchTheSecondter = \DateTime::createFromFormat('Y-m-d H:i:s', '2001-03-02 00:01:00');
$interval3 = $FebruaryTheFirstter->diff($MarchTheSecondter);
echo $interval3->m.PHP_EOL; // Outputs 0. WTF?
$FebruaryTheFirstfour = \DateTime::createFromFormat('Y-m-d H:i:s', '2001-02-01 01:00:00');
$MarchTheSecondfour = \DateTime::createFromFormat('Y-m-d H:i:s', '2001-03-02 01:00:00');
$interval4 = $FebruaryTheFirstfour->diff($MarchTheSecondfour);
echo $interval4->m.PHP_EOL; // Outputs 1. WTF?
問題
我應該總是讓1
作爲輸出,因爲我總是之間計數月份的數字Februar,1日和3月1日。但如前所示,我也得到0
=> WTF?
的信息我的PHP版本是
PHP 5.3.8 (cli) (built: Jan 12 2012 19:12:32) Copyright (c) 1997-2011
The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend
Technologies with Xdebug v2.1.1, Copyright (c) 2002-2011, by Derick Rethans
什麼是你的問題正是 – 2012-02-06 16:24:08
@Topener:我編輯更精確。我的問題是爲什麼輸出變化,哪裏沒有。 – 2012-02-06 16:49:09
我無法在5.3.6和5.4.0-rc7,1中直接複製此行爲。 – Charles 2012-02-06 16:52:50