代码如下

function countDown($endTime){
    $endTime = strtotime($endTime);
    $beiginTime = strtotime(date('Y-m-d H:i:s'));
    $timeDifference = $endTime - $beiginTime;
    switch ($timeDifference){
        case $timeDifference < 0 :
             $timeDifference = '已经结束!';
             break;
        case $timeDifference < 60 :
             $timeDifference = $timeDifference.'秒';
             break;
        case $timeDifference < 3600 :
             $minutes = floor($timeDifference/60);
             $seconds = floor($timeDifference - ($minutes*60));
             $timeDifference = $minutes.'分'.$seconds.'秒';
             break;
        case $timeDifference < 86400 :
             $hours = floor($timeDifference/3600);
             $minutes = floor(($timeDifference - ($hours*3600))/60);
             $seconds = floor($timeDifference - ($hours*3600) - ($minutes*60));
             $timeDifference = $hours.'小时'.$minutes.'分'.$seconds.'秒';
             break;
        default:
             $days = floor(($timeDifference/86400));
             $hours = floor(($timeDifference - ($days*86400))/3600);
             $minutes = floor(($timeDifference - ($days*86400) - ($hours*3600))/60);
             $seconds = floor($timeDifference - ($days*86400) - ($hours*3600) - ($minutes*60));
             $timeDifference = $days.'天'.$hours.'小时'.$minutes.'分'.$seconds.'秒';
             break;
    }
    return $timeDifference;
}
最后修改:2020 年 03 月 22 日 08 : 46 PM