//strtotime 时间转为时间戳 /** * @param $actionTime * @param $endTime */ function demo($actionTime,$endTime){ if (strtotime($endTime) < strtotime($actionTime)){ echo '活动超时啦 宝~'; } $diff = strtotime($endTime) - strtotime($actionTime); $day = floor($diff/(3600*24)); $diff = $diff%(3600*24); //除去整天之后剩余的时间 $hour = floor($diff/3600); $diff = $diff%3600; //除去整小时之后剩余的时间 $minute = floor($diff/60); $second = $diff%60; //除去整分钟之后剩余的时间 echo '还剩' . $day.'天'.$hour.'小时'.$minute .'分钟' . $second . '秒'; } echo demo('2021-09-07 22:00','2022-09-07 22:00');