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) from & nbsp; 1970 & nbsp; year & nbsp; 1 & nbsp; month & nbsp; 1 & nbsp; day to & nbsp; 2038 & nbsp; year & nbsp; 1 & nbsp; php timestamp
This post was last edited by hongming271 at 16:20:16
In php functions, the date function is limited in some systems (such as Windows) from January 1, January 1-20, 1970 to January 1, January 19.
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 --------------------
This post was last edited by xuzuning at 09:41:27 on
DateTime: format is 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