【问题标题】:In PHP why use @Epochtime在 PHP 中为什么使用 @Epochtime
【发布时间】:2017-07-11 16:55:31
【问题描述】:

我在

找到了这个示例代码

http://www.epochconverter.com/programming/php

$epoch = 1483228800;
$dt = new DateTime("@$epoch");  // convert UNIX timestamp to PHP DateTime
echo $dt->format('Y-m-d H:i:s'); // output = 2017-01-01 00:00:00

我想了解为什么使用@符号以及如果输入如下,为什么 DateTime() 不转换

$dt  = new DateTime($epoch);

【问题讨论】:

    标签: php datetime epoch date-conversion


    【解决方案1】:

    它是解析器识别的格式。 More about supported formats in official documentation

    为什么要@ 签名?好吧,让我们将日期 1970-01-01 00:33:37 作为时间戳 - 它是 2017。看起来像今年,不是吗?因此,为了确保您传递的是时间戳,而不是模棱两可的东西,它以 @ 为前缀。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-23
      • 1970-01-01
      • 2019-11-16
      • 2016-10-08
      • 2010-11-26
      • 2020-08-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多