思路是先求两个时间的秒数差,然后将结果转换即可:
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';
}