2个日期之间的差异,以秒为单位 [英] Difference between 2 dates in seconds
问题描述
可能的重复:
从现在()到星期日午夜的秒数
计算PHP中两个日期之间的差异
Hello All,
在我的项目中,我需要计算两个日期之间的差异:
例如:
$ firstDay =2011-05-12 18: 20:20
$ secondDay =2011-05-13 18:20:20;
然后我应该得到 86400秒这是24小时。
同样对于
$ firstDay =2011-05-13 11:59:20
$ secondDay =2011-05-13 12:00:20;
应该返回 60秒。
我在 stackoverflow中阅读了很多问题但是他们只处理
与 2分钟字段之间的区别 11:50:01和12:10:57
$ timeFirst = strtotime('2011-05-12 18:20:20');
$ timeSecond = strtotime('2011-05-13 18:20:20');
$ differenceInSeconds = $ timeSecond - $ timeFirst;
然后,您可以使用秒钟查找分钟,小时,天等。 p>
Possible Duplicates:
Number of seconds from now() to Sunday midnight
Calculates difference between two dates in PHP
Hello All,
In my project, I need to calculate the difference in seconds between two dates:
For Example :
$firstDay = "2011-05-12 18:20:20";
$secondDay = "2011-05-13 18:20:20";
Then I should get 86400 Seconds That is 24 hours.
Similarly For
$firstDay = "2011-05-13 11:59:20";
$secondDay = "2011-05-13 12:00:20";
It should return 60 Seconds.
I read lots of questions in the stackoverflow But they only deals
with the difference between 2 minute fields like 11:50:01 and 12:10:57
$timeFirst = strtotime('2011-05-12 18:20:20');
$timeSecond = strtotime('2011-05-13 18:20:20');
$differenceInSeconds = $timeSecond - $timeFirst;
You will then be able to use the seconds to find minutes, hours, days, etc.
这篇关于2个日期之间的差异,以秒为单位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!