这篇文章主要介绍了php简单计算两个时间差的方法,结合具体实例形式分析了php日期与时间的转换及数学运算相关操作技巧,需要的朋友可以参考下
本文实例讲述了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实现时间比较和时间差计算的方法(实例)
php计算时间差
php计算两个时间差的方法
以上就是php实现计算两个时间差的方法的详细内容。