编程语言
首页 > 编程语言> > PHP--计算两个日期之间相差的天数/小时/分钟/秒数

PHP--计算两个日期之间相差的天数/小时/分钟/秒数

作者:互联网

$res = '2019-07-24 10:10:00';
$rea = date('Y-m-d H:i:s');

$date = (strtotime($rea) - strtotime($res)) / 86400;//计算两个日期相隔天数
echo $date . '<br/>';
$hour = (strtotime($rea) - strtotime($res))%86400/3600;//计算两个日期相隔小时
echo $hour . '<br/>';
$mid = (strtotime($rea) - strtotime($res))%86400/60;//计算两个日期相隔分钟
echo $mid . '<br/>';
$sec = strtotime($rea) - strtotime($res);//计算两个日期相隔秒数
echo $sec . '<br/>';
if ((strtotime($rea) - strtotime($res)) > 24*3600) {
	echo 'yes';
} else {
	echo 'no';
}

 

标签:rea,秒数,天数,echo,strtotime,86400,res,date,PHP
来源: https://blog.csdn.net/qq_42176520/article/details/100014167