PHP strtotime 作为 UTC 时间戳返回?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6275614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP strtotime to return as UTC timestamp?
提问by Good-bye
Its a bit of a sever difference problem. On my local dev. server Im using:
它有点严重的差异问题。在我的本地开发人员上。服务器我使用:
<?php print strtotime($date." UCT"); ?>
The above code gives me the correct timestamp for my timezone. HOWEVER, the same code returns false on the live server.
上面的代码为我的时区提供了正确的时间戳。但是,相同的代码在实时服务器上返回 false。
The live server has a lower version of php installed and I imagine that to be the problem.
实时服务器安装了较低版本的 php,我认为这是问题所在。
What I'm looking for is an alternative to the above line of code.
我正在寻找的是上述代码行的替代方法。
I could use the normal strototime without the ." UCT" part and add in 2hours but would rather have PHP handle timezones.
我可以使用没有 ." UCT" 部分的普通 strototime 并添加 2 小时,但宁愿让 PHP 处理时区。
$date looks like this: 2011-05-25 05:48:00
$date 看起来像这样:2011-05-25 05:48:00
回答by ajreal
<?php print strtotime($date." UTC"); ?>
instead of
代替
<?php print strtotime($date." UCT"); ?>
回答by DhruvPathak
PHP warning on PHP documentation page, no support for UCT there :
PHP 文档页面上的 PHP 警告,那里不支持 UCT:
http://www.php.net/manual/en/timezones.others.php
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.
And here is latest PECL timezon database :
这是最新的 PECL 时区数据库: