如何將代碼轉換成以小時爲單位的天數?php date_diff以小時爲單位
$timestart = date_create('02/11/2011' . $row->timestart); //$row->timestart returns time in 00:00:00 format
$timestop = date_create('02/11/2011' . $row->timestop); //$row->timestop returns time in 00:00:00 format
date_add($timestop, date_interval_create_from_date_string('2 days')); //add 2 days
$date_diff = date_diff($timestart, $timestop);
echo "Timespan: ";
echo $date_diff->format('%h hours');
echo "<br />";
我怎樣才能得到hours:minutes:seconds
已過?我正在嘗試使用date_diff
函數。
您應該使用'DateTime'的對象樣式。 –
@Truth,程序風格有什麼問題?它似乎給出了相同的結果。 – CyberJunkie
它確實給出了相同的結果,使用DateTime對象比使用過程函數更容易。它也[看起來更好](https://gist.github.com/2942405) –