Home > Article > Backend Development > How to calculate the difference between two times in PHP
This article mainly introduces the method of PHP to simply calculate the difference between two times, and analyzes the conversion of PHP date and time and related operation techniques of mathematical operations in the form of specific examples. Friends in need can refer to it. I hope it can help everyone.
<?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>";
Run results:
##
732天 0小时 12分钟 12秒Related recommendations:
PHP time comparison and time difference calculation implementation code
Detailed explanation of PHP time difference calculation method
Sharing on how PHP implements time comparison and time difference calculation methods
The above is the detailed content of How to calculate the difference between two times in PHP. For more information, please follow other related articles on the PHP Chinese website!