简体   繁体   English

PHP中的strtotime()转换错误

[英]Error in strtotime() conversion in PHP

My variable $createdDate has a value '2014-06-23T01:44:22Z' something like this in it. 我的变量$createdDate的值为'2014-06-23T01:44:22Z' It's fetched from database. 它是从数据库中获取的。

And when I convert it into standard format using strtotime(), the time returned is always 2 hours different(ahead) from the orginal variable's time. 当我使用strtotime()将其转换为标准格式时,返回的时间总是与原始变量的时间相差2小时(提前)。

$time1 = strtotime($createdDate);
$cretime_formated=date("Y-m-d h:i:s",$time1);

Output of $cretime_formated is 2014-06-23 03:44:22 instead of 2014-06-23 01:44:22 . $cretime_formated输出是2014-06-23 03:44:22而不是2014-06-23 01:44:22 Why is there a difference of 2 hours in the time??? 为什么时间会相差2个小时??? Is there anything wrong with my conversion process?? 我的转换过程有什么问题吗?

鉴于日期在Zulu时区中(并且假设所有此类时间戳都在同一时区中),则需要gmdate()进行格式化:

$cretime_formated = gmdate("Y-m-d h:i:s",$time1);

I think you have the time difference .You need to set it in UTC 我认为您有时差。您需要在UTC进行设置

date_default_timezone_set('UTC');

See Complete Refrence 参见完全参考

List of Supported Timezones 支持的时区列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM