Php timestamp question this post was last edited by the date function in the php function from 2013-03-0516: 20: 16 on hongming271 in some systems (such as & nbsp; Windows) it is limited to the timestamp issue of from & nbsp; 1970 & nbsp; year & nbsp; 1 & nbsp; month & nbsp; 1 & nbs php
At the end of this post, the date function in the php function was edited by hongming271 at January 1-20, 1970 16:20:16 on January 19. in some systems (such as Windows), the date function is limited to from.
Now I have a timestamp that exceeds 2038 and cannot be converted to the correct standard time format using date.
Another problem is that I have a timestamp of 1356969600, and the normal result is 00:00:00.
Example
$dt = new DateTime('@1356969600');
echo $dt->format('Y-m-d H:i:s');
The example is converted to 16:00:00, which is eight hours less than the normal effect.
------ Solution --------------------
Date_default_timezone_set ("Europe/London ");
$ Dt = new DateTime ('@ 1356969600 ');
Echo $ dt-> getTimezone ()-> getName (), "\ n ";
Echo $ dt-> format ('Y-m-d H: I: s'), "\ n ";
Echo date ('Y-m-d H: I: s ', 1356969600), "\ n ";
Date_default_timezone_set ("Asia/Shanghai ");
$ Dt = new DateTime ('@ 1356969600 ');
Echo $ dt-> getTimezone ()-> getName (), "\ n ";
Echo $ dt-> format ('Y-m-d H: I: s'), "\ n ";
Echo date ('Y-m-d H: I: s ', 1356969600), "\ n ";
Date_default_timezone_set ("Asia/Shanghai ");
$ Dt = new DateTime ('@ 1356969600 ');
Echo $ dt-> getTimezone ()-> getName (), "\ n ";
Echo $ dt-> format ('Y-m-d H: I: s'), "\ n ";
Echo date ('Y-m-d H: I: s ', 1356969600), "\ n ";
$ Dt-> setTimezone (new DateTimeZone ('Asia/Shanghai '));
Echo $ dt-> getTimezone ()-> getName (), "\ n ";
Echo $ dt-> format ('Y-m-d H: I: s'), "\ n ";
Echo date ('Y-m-d H: I: s ', 1356969600), "\ n ";
------ Solution --------------------
At the end of this post, xuzuning edited DateTime: format at 09:41:27 on was designed not to be affected by external settings (this should be the case for object-oriented)
Therefore, no matter how you change the environment parameter date_default_timezone, the output results are not affected.
To change the time zone of DateTime: format
DateTime: setTimezone: input a time zone object DateTimeZone
For example
$d = new DateTime('@1356969600');
$d->setTimezone(new DateTimeZone('PRC'));
echo $d->format('Y-m-d H:i:s');
00:00:00