php 以秒为单位的两个日期之间的差异
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5988450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between 2 dates in seconds
提问by Pushpendra
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 SecondsThat is 24 hours.
那么我应该得到86400 Seconds即 24 小时。
Similarly For
同样对于
$firstDay = "2011-05-13 11:59:20";
$secondDay = "2011-05-13 12:00:20";
It should return 60 Seconds.
它应该返回60 秒。
I read lots of questions in the stackoverflow But they only deals
with the difference between 2 minute fieldslike 11:50:01 and 12:10:57
我在11:50:01 和 12:10:57等2 分钟字段stackoverflow But they only deals
之间阅读了很多问题
回答by Jordonias
$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.
然后,您将能够使用秒来查找分钟、小时、天等。