【问题标题】:Not properly converting epoch time to normal time in PHP在 PHP 中未正确将纪元时间转换为正常时间
【发布时间】:2016-03-06 06:54:03
【问题描述】:

这是我用来在 PHP 中将 EPOCH 时间转换为正常时间的代码。我没有将时区设置为不需要。在以下代码中,$timeD 是输入时间,在 http://www.epochconverter.com/ 中正确转换

 $timeD = 1449034934000;
 echo gmdate('r', $timeD);

预计输出时间为 2015 年 12 月 2 日上午 11:12:14 GMT+5:30。但得到的是

47888 年 2 月 8 日星期三 14:56:40 +0000

【问题讨论】:

    标签: php epoch


    【解决方案1】:

    您使用的时间具有毫秒精度(可能来自 Javascript),因此您只需将时间戳的最后三位数字去掉即可。 14490349341449034934<strong>000</strong>

    $timeD = 1449034934000; //$timeD = 1449034934; is what we want.
    $timeD = substr($timeD,0,10); // Chop off those pesky unnecessary milliseconds!
    echo gmdate('r', $timeD);
    

    【讨论】:

    • 谢谢你加载老兄..你解决了我的问题。再次感谢你。如果你能指导我下一步,我会更感激你。如何在您的程序输出中添加 +5.30 小时。
    • @yudihukkeri 这可能对你有用:echo date('m/d/Y h:i:sA P',$timeD); 对我来说我得到12/01/2015 09:42:14PM -08:00 .. 我在不同的时区,所以让我知道它是否需要调整
    • 感谢 cmets @nextlocal
    猜你喜欢
    • 2011-03-08
    • 2019-12-08
    • 2012-06-06
    • 2021-11-10
    • 2020-02-22
    • 1970-01-01
    • 2012-01-30
    • 2019-07-20
    • 2021-12-20
    相关资源
    最近更新 更多