$start_hour = strtotime('2030');
$end_hour = strtotime('0100');
$resthour = abs(gmdate (strtotime($end_hour)- strtotime($start_hour)))/3600;
我当前的输出是19.5。我期望的结果应该是4.5。
是否有更好的方法来推导呢?谢谢你。
您已接近所需的结果,只需添加一条简单的代码行即可检查是否少于12小时,否则进行转换
$resthour = ($resthour >= 12) ? $resthour : 24 - $resthour;
这将起作用。
问候,
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句