如何在PHP中计算两个时间差
更新:HHH   时间:2023-1-7


这篇文章给大家介绍如何在PHP中计算两个时间差,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

具体如下:

<?php
//PHP计算两个时间差的方法 
$startdate="2010-12-11 11:40:00";
$enddate="2012-12-12 11:45:09";
$date=floor((strtotime($enddate)-strtotime($startdate))/86400);
$hour=floor((strtotime($enddate)-strtotime($startdate))/86400/3600);
$minute=floor((strtotime($enddate)-strtotime($startdate))/86400/60);
$second=floor((strtotime($enddate)-strtotime($startdate))/86400/60);
echo $date."天<br>";
echo $hour."小时<br>";
echo $minute."分钟<br>";
echo $second."秒<br>";

运行结果:

732天
0小时
12分钟
12秒

关于如何在PHP中计算两个时间差就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

返回开发技术教程...