【问题标题】:wrong conversion in strtotime & in date() for 13458102031345810203 在 strtotime 和 date() 中的错误转换
【发布时间】:2012-08-24 12:35:29
【问题描述】:

我想存储开始时间和结束时间并计算两次之间的总时间差。有时我会因为这个问题得到像-1 min -24 sec 这样的负时间...

如果我回显此代码

date('Y-m-d h:m:s',1345810203);

我得到了2012-08-24 02:08:03 的答案,但我回显了这段代码

strtotime('2012-08-24 02:08:03');

我得到了1345766883的答案。

如果时间是1345810167 或1345810187,在strtotime & date() 中给出正确的时间。

有什么问题?

【问题讨论】:

    标签: php


    【解决方案1】:

    格式错误。

    m 是Numeric representation of a month, with leading zeros

    i 是Minutes with leading zeros

    使用以下格式:

    'Y-m-d h:i:s'
    

    参考:http://php.net/manual/en/function.date.php

    【讨论】:

    • 第三杯咖啡发挥了作用。 8-)
    • @rhrobert 不客气。此外,您应该在答案分数下方打勾来标记正确答案。你最近的问题也应该这样做!
    猜你喜欢
    • 2012-02-21
    • 2011-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-15
    • 1970-01-01
    • 1970-01-01
    • 2017-08-20
    相关资源
    最近更新 更多