计算当前时间到结束时间的剩余时分:
输入参数:
$endTime = "2021-02-25 16:58:01";
echo '截止时间(日期):'.$endTime;
echo "<pre>";
echo '当前时间(日期):'.date('Y-m-d H:i:s');
$endTime = strtotime("2021-02-25 16:58:01");
echo "<pre>";
$time = $endTime - time();
echo '剩余时间(秒):'.$time;
echo "<pre>";
//计算倒计时
$res = getHourStr($time);
echo '倒计时(时分):'.$res;
剩余时分计算:
function getHourStr($time)
{
if ($time < 0) {
return "已超时";
}
$hour = floor($time / 3600);
$min = floor(($time - $hour * 3600) / 60);
return $hour . '时' . $min . '分';
}
打印结果: