PHP中的strtotime如何返回UTC时间戳?

12

这是一个比较严重的问题。在我的本地开发服务器上,我使用的是:

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

以上代码在我的时区中给出了正确的时间戳。但是,在实际服务器上,同样的代码返回false。

我想这是因为实际服务器上安装了较低版本的php。

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

我可以使用普通的strtotime而不带". UCT"部分,并添加2个小时,但我更愿意让PHP处理时区。

$date的格式如下:2011-05-25 05:48:00


现场服务器上的PHP版本是什么? - Roshan Wijesena
$date看起来是什么样子?你是不是想说UTC而不是UCT? - Salman A
3
<?php print strtotime($date." UTC"); ?> 这段代码有效吗? - Matthew
@Roshan 5.2.6 @是的,错别字已经更正。$date = 2011-05-25 05:48:00 - CodeChap
2个回答

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

替代

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

1
@stefgosselin UCT也是一个有效的时区。http://www.php.net/manual/en/timezones.others.php - DhruvPathak
2
Please do not use any of the timezones listed here (besides UTC), they only exist for backward compatible reasons. - ajreal

0

1
明显不指出@Good-bye可能打错字是不礼貌的。 - capikaw
@capikaw 或许是因为这不是一个错别字。UCT 是“协调世界时”的支持名称,但在 PHP 中不被支持,这就是我在答案中提到的。例如,可以看看 Linux:ls /usr/share/zoneinfo/U* /usr/share/zoneinfo/UCT /usr/share/zoneinfo/Universal /usr/share/zoneinfo/UTC。在我看来,错误的点赞也是很无礼的。 - DhruvPathak

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接