php计算指定日期剩余多少天

发布时间:2021年09月24日 阅读:219 次

思路是先求两个时间的秒数差,然后将结果转换即可:

PHP
echo calcTime('2018-08-20', '2018-08-30');function calcTime($fromTime, $toTime){
     
    //转时间戳
    $fromTime = strtotime($fromTime);
    $toTime = strtotime($toTime);
    //计算bai时间差
    $newTime = $toTime - $fromTime;
    return round($newTime / 86400) . '天' . 
    round($newTime % 86400 / 3600) . '小时' . 
    round($newTime % 86400 % 3600 / 60) . '分钟du';
     }


Tag:
相关文章