【问题标题】:Subtract seconds from a specific given time PHP [duplicate]从特定的给定时间PHP中减去秒[重复]
【发布时间】:2014-03-16 12:17:49
【问题描述】:

我使用 php 编写了一个从时间中减去秒数的代码。我有分配给变量的日期,我需要从该日期中减去秒数。

$date="2014-03-16 17:40:27";
echo date("Y-m-d H:i:s", strtotime($date) - strtotime("-600 seconds"));

但这给了我 1970 年代的日期,我在这里搜索并没有找到与我的问题相匹配的答案。谁能帮我修复这个小代码

【问题讨论】:

    标签: php datetime


    【解决方案1】:

    strtotime() 为您提供以秒为单位的时间戳。不要再做一个时间戳来减去它,只需从中减去 600:

    echo date("Y-m-d H:i:s", strtotime($date) - 600);
    //2014-03-16 17:30:27
    

    【讨论】:

    • 工作得很好,非常感谢 :)
    • @SunethKalhara 很高兴能帮上忙。
    猜你喜欢
    • 2012-10-04
    • 1970-01-01
    • 2017-06-11
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2012-09-04
    • 1970-01-01
    相关资源
    最近更新 更多