我数据库中的时间戳是2015-03-03 00:25:39
(请注意,type = timestamp
我最后正确的当前时间戳是2015-03-02 01:31:00
。差异应该在 23 小时左右。但现在的问题是网络中提供的答案会给我 30 小时而不是 23 小时. 我尝试过的一些代码如下:
$target
是目标日期
CODE 1:
$then = strtotime($target);
$diff = $then - time();
echo sprintf("%s days and %s hours left", date('z', $diff), date('G', $diff));
但这给了我1天6小时的时间。所以30 hours
CODE2:
$seconds = strtotime("$target") - time();
echo $seconds; exit();
$days = floor($seconds / 86400);
$seconds %= 86400;
$hours = floor($seconds / 3600);
echo $hours;
它给了我大约107388
30 小时的时间。
CODE 3:
//Convert to date
$datestr= $target;//Your date
$date=strtotime($datestr);//Converted to a PHP date (a second count)
//Calculate difference
$diff=$date-time();//time returns current time in seconds
$days=floor($diff/(60*60*24));//seconds/minute*minutes/hour*hours/day)
$hours=round(($diff-$days*60*60*24)/(60*60));
它给了我6个小时
我不知道我做错了什么,更像是我不知道该怎么做。这是我现在的最后手段,因为我找不到对我有帮助的解决方案。希望您的快速响应。