php 计算两个日期 时间差 展示天时分秒

评论3,179
use DateTime;

$start_date="2022-07-13 08:50:00";//开始时间
$end_date="2022-07-14 12:12:12";//结束时间

echo "开始时间:".$start_date."<br><br>";
echo "结束时间:".$end_date."<br><br>";

$start_date = new DateTime($start_date);
$since_start = $start_date->diff(new DateTime($end_date));
//echo "相差年数:".$since_start->y.'年<br>';
//echo "相差月数:".$since_start->m.'月<br>';
echo "相差天数:".$since_start->d.'天<br>';
echo "相差小时数:".$since_start->h.'小时<br>';
echo "相差分钟数:".$since_start->i.'分钟<br>';
echo "相差秒数:".$since_start->s.'秒<br>';

 最后更新:2023-1-12

发表评论