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