Php 把剩下的时间留到早上

Php 把剩下的时间留到早上,php,time,Php,Time,我想争取早上8点的剩余时间 我试过这个: $hours = current_time('H'); $now = current_time( 'timestamp' ); $tomorrow = strtotime('tomorrow +8Hours', current_time( 'timestamp' )); floor(($tomorrow - $now) / (60 * 60)) ; 但在早上,它会转移到明天的日期 请告诉我如何计算上午8点的剩余时间(小时)。明天早上8点以后数数 谢

我想争取早上8点的剩余时间

我试过这个:

$hours = current_time('H');

$now = current_time( 'timestamp' );
$tomorrow = strtotime('tomorrow +8Hours', current_time( 'timestamp' ));

floor(($tomorrow - $now) / (60 * 60)) ;
但在早上,它会转移到明天的日期

请告诉我如何计算上午8点的剩余时间(小时)。明天早上8点以后数数

谢谢。

您可以创建两个对象,并使用以下方法计算两者之间的差异:


你还试过什么?如果你总是做
“明天+8小时”
,不管发生什么,这不是预期的吗?什么是
当前时间?顺便说一句,编程就是将算法从人类语言转换成代码。您如何解释需要由某些人执行哪些步骤才能获得结果?比如:1。以当前时间为例。提取第三部分的时间。如果。。。4.…@kingkero你不明白我的问题吗<代码>楼层($明天-$现在)/(60*60))我一直在重读这篇文章,但我仍然不知道你在找什么。你能详细解释一下吗?@johncode我猜OP希望剩下的时间是(下一个)上午8点。如果晚上10点->10小时,上午4点->4小时。但由于他测量的是“明天早上8点”:凌晨4点->28小时
$now = new DateTime();
$eight = new DateTime('08:00:00');

if ($now->format('H:i:s') > '08:00:00') {
  $eight->modify('+1 day');
}

$interval = $eight->diff($now);

echo $interval->format('%H:%I:%S');