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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:06:37  来源:igfitidea点击:

Difference between 2 dates in seconds

phpdate

提问by Pushpendra

Possible Duplicates:
Number of seconds from now() to Sunday midnight
Calculates difference between two dates in PHP

可能的重复:
从 now() 到周日午夜的秒数
计算 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 dealswith the difference between 2 minute fieldslike 11:50:01 and 12:10:57

我在11:50:01 和 12:10:572 分钟字段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.

然后,您将能够使用秒来查找分钟、小时、天等。