这篇文章主要介绍了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>";
立即学习“PHP免费学习笔记(深入)”;
运行结果:
732天 0小时 12分钟 12秒
立即学习“PHP免费学习笔记(深入)”;
相关推荐:
立即学习“PHP免费学习笔记(深入)”;
以上就是PHP实现计算两个时间差的方法的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号