0
我試圖計算$ timenow和$ time之間的差異。2時間戳之間的差異 - PHP
$time = 2016-09-15 20:10:35
$timenow = 2016-09-15 20:40:42
我將它們轉換爲dateTime。
$time = new DateTime($time);
$timenow = new DateTime($timenow);
,然後做了計算:
$interval = $timenow->diff($time);
echo $interval;
錯誤:開捕致命錯誤:類DateInterval的對象無法轉換爲字符串
我看着這些 difference between 2 timestamps in php 和 Wrong hour difference between 2 timestamps (hh:mm:ss)
那些沒有幫助。
'$ interval'是一個對象,你需要對其進行格式化。 http://php.net/manual/en/datetime.format.php - 例如,'$ interval-> format('Ymd H:i:s');' – Qirel
您可能想要使用'format'該對象http://php.net/manual/en/dateinterval.format.php –
可能重複的[php類的DateInterval對象不能轉換爲字符串](http://stackoverflow.com/questions/28621270/php -class-dateinterval-could-be-converted-to-string) – HPierce