【问题标题】:Difference between 2 dates in seconds [duplicate]以秒为单位的2个日期之间的差异[重复]
【发布时间】:2011-08-24 17:05:03
【问题描述】:

可能的重复:
Number of seconds from now() to Sunday midnight
Calculates difference between two dates in PHP

大家好,

在我的项目中,我需要计算两个日期之间的秒差:

例如:

$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 But they only deals 中阅读了很多关于2 分钟字段 之间的区别,例如11:50:01 和12:10:57

【问题讨论】:

标签: php date


【解决方案1】:
$timeFirst  = strtotime('2011-05-12 18:20:20');
$timeSecond = strtotime('2011-05-13 18:20:20');
$differenceInSeconds = $timeSecond - $timeFirst;

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-02
    • 2011-04-27
    • 2020-11-28
    • 1970-01-01
    • 2012-09-13
    • 1970-01-01
    相关资源
    最近更新 更多