$dbtime = $row["dateupload"];
print_r($dbtime); //- DATE FORMAT: 2020-02-21 22:24:00
echo("<br>");
$servertime = date('Y-m-d h:i:s', time());
print_r($servertime); //- DATE FORMAT: 2020-02-21 22:24:00
$totaltime = $dbtime - $servertime;
$etime = $totaltime; //- A non well formed numeric value encountered in
if ($etime < 1)
{
return '0 seconds';
}
尝试使用字符串格式,但这是显示正确的结果,现在在print_r,缺少什么?
use date_diff():
https://www.php.net/manual/en/datetime.diff.php
<?php
$origin = date_create('2009-10-11');
$target = date_create('2009-10-13');
$interval = date_diff($origin, $target);
echo $interval->format('%R%a days');
或使用$object_of_DateTime->diff()
$origin = new DateTime('2009-10-11');
$target = new DateTime('2009-10-13');
$interval = $origin->diff($target);
echo $interval->format('%R%a days');
否则使用Unix时间戳格式,如1613953162
所以你可以使用
$diffrent_in_second = 1613953162-1613953151 // 11 seconds