php里边,如何实现以下算法:
现在是17日17:08,如何计算17:08到24:00(即18日0:00)的时间间隔是多久?
先谢谢各位了!
$now = time();
$over = strtotime(date("y-m-d 23:59:59",$now));
$dif = $over - $now;
$over = strtotime(date("y-m-d 23:59:59",$now));
$dif = $over - $now;
应该可以,返回时间间隔为单位为秒
温馨提示:答案为网友推荐,仅供参考
第1个回答 2015-09-24
strtotime()函数的作用是将日期时间描述解析为 Unix 时间戳
int strtotime ( string time [, int now] )
<?//1. 获取明天的日期
$tomo = date("Y-m-d",strtotime("+1 day"));
//2. 明天凌晨的时间减去现在的时间,获取到24点的时间间隔
$seconds = strtotime($tomo) - time();
echo "到24点还差:".changeTimeType($seconds);
function changeTimeType($seconds) {
if ($seconds > 3600) {
$hours = intval($seconds / 3600);
$minutes = $seconds % 3600;
$time = $hours . ":" . gmstrftime('%M:%S', $minutes);
} else {
$time = gmstrftime('%H:%M:%S', $seconds);
}
return $time;
}
?>
第2个回答 2013-10-17
strtotime(date('Y-m-d 00:00:00',time()+86400))-time()
第3个回答 2013-10-18
获取系统当前时间,然后在跟23.59.59之间相减