【问题标题】:PHP strtotime to return as UTC timestamp?PHP strtotime作为UTC时间戳返回?
【发布时间】:2011-06-08 07:38:46
【问题描述】:

它有点严重的差异问题。在我的本地开发人员上。我正在使用的服务器:

<?php print strtotime($date." UCT"); ?>

上面的代码为我的时区提供了正确的时间戳。但是,相同的代码在实时服务器上返回 false。

实时服务器安装了较低版本的 php,我想这是问题所在。

我正在寻找的是上述代码行的替代方法。

我可以使用没有 ."UCT" 部分的正常 strototime 并添加 2 小时,但宁愿让 PHP 处理时区。

$date 如下所示:2011-05-25 05:48:00

【问题讨论】:

  • 实时服务器上的php版本是什么
  • $date 是什么样的?你的意思是 UTC 而不是 UCT?
  • &lt;?php print strtotime($date." UTC"); ?&gt; 工作吗?
  • @Roshan 5.2.6 @是的,错字已更正。 $日期 = 2011-05-25 05:48:00

标签: php timestamp strtotime


【解决方案1】:
<?php print strtotime($date." UTC"); ?>

而不是

<?php print strtotime($date." UCT"); ?>

【讨论】:

  • @stefgosselin UCT 也是有效时区。 php.net/manual/en/timezones.others.php
  • Please do not use any of the timezones listed here (besides UTC), they only exist for backward compatible reasons.
【解决方案2】:

PHP 文档页面上的 PHP 警告,那里不支持 UCT:

http://www.php.net/manual/en/timezones.others.php

Warning

Please do not use any of the timezones listed here (besides UTC), they only exist for backward compatible reasons.

这是最新的 PECL 时区数据库:

http://pecl.php.net/get/timezonedb

【讨论】:

  • 公然没有指出@Good-bye 可能打错字是不礼貌的。
  • @capikaw 或者可能是因为它不是拼写错误,UCT 是 "Universal Coordinated Time" 的受支持名称,但在 PHP 中不受支持,这就是我在回答中提到的。例如,请参见 linux:` ls /usr/share/zoneinfo/U* /usr/share/zoneinfo/UCT /usr/share/zoneinfo/Universal /usr/share/zoneinfo/UTC` 错误的反对意见也是粗鲁的恕我直言。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-29
  • 2011-06-16
  • 2019-09-02
  • 2012-07-24
  • 1970-01-01
相关资源
最近更新 更多