2个日期(秒)的差值[重复]

时间:2021-06-18 21:27:41

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 Seconds That is 24 hours.

那么我应该得到86400秒也就是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 * But they only deals with the difference between 2 minute fields like 11:50:01 and 12:10:57

我在*上读了很多问题,但是它们只讨论了11:50:01和12:10:57之间的区别

1 个解决方案

#1


127  

$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.

然后你就可以用秒来找出分钟、小时、天等等。

#1


127  

$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.

然后你就可以用秒来找出分钟、小时、天等等。