可能重複:
How to get aggregate days from PHP's DateTime::diff?爲DateInterval ::格式功能不可預期的結果
我有這樣的事情:
$daysDiff = intval($currentDate->diff($dueDate)->format('%R%a'));
爲DateInterval的PHP文件中: :格式說:
%R -- "+" for positive interval, "-" for negative
%a -- the total count of days i the interval
我對結果有麻煩,總是將6015換成天,並帶正確的符號+或 - 。 我用$currentdate
和$dueDate
的不同日期嘗試。 任何人都可以告訴我爲什麼會出現這種行爲。
謝謝
能否請您補充一點,你使用了'$ currentDate'和'$ dueDate'的價值? – andrewsi
$ currentDate = new \ DateTime() $ dueDate是從數據庫中獲取的值,是一個有效的DateTime對象,並且始終(即使使用不同的值)獲得那些6015天的差異。 – Oriam