更新时间:2023-02-05 20:44:00
diff
将返回一个DateInterval对象,该对象包含有关两个日期之间的差的详细信息。您只是在尝试回显无效的对象。执行 var_dump()
来查看对象的属性:
diff
is going to return a DateInterval object full of good information about the difference between your two dates. You're just trying to echo that object which won't work. Do a var_dump()
to see the object's properties:
$time = "2016-09-15 20:10:35";
$timenow = "2016-09-15 20:40:42";
$time = new DateTime($time);
$timenow = new DateTime($timenow);
$interval = $timenow->diff($time);
var_dump($interval);
然后,您可以回显以下属性:
Then you can echo out the properties like:
echo $interval->i; // minutes
// 30