The date function in PHP functions is limited to some systems, such as Windows, from January 1, 1970 to January 19, 2038.
Now I have a time stamp that is more than 2038 years old and does not normally translate into the correct standard time format with date.
Another problem is that I have a time stamp 1356969600, which translates into a normal effect of 2013-1-1 00:00:00
Example
$dt = new DateTime (' @1356969600 '), Echo $dt->format (' y-m-d h:i:s ');
The example conversion turned out to be 2012-12-31 16:00:00, eight hours less than the normal effect.
Reply to discussion (solution)
Date_default_timezone_set ("PRC");
Let's try this sentence.
Date_default_timezone_set ("PRC");
Let's try this sentence.
This useless, this timestamp is not real-time update, is the past time, so useless, you can try
8 hours is because China is in district +8.
It's best to change timezone in php.ini.
The timestamp is the number of seconds starting January 1, 1970, regardless of the time zone.
Manual: http://www.php.net/manual/en/datetime.construct.php
//Using a UNIX Timestamp. Notice The result is in the UTC time zone.
$date = new DateTime (' @946684800 ');
Echo $date->format (' y-m-d h:i:sp '). "\ n";
!--? php
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";
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 ...
echo $dt->format (' y-m-d h:i:s '), "\ n"; 2012-12-31 16:00:00
Date (' y-m-d h:i:s ', 1356969600), "\ n"; 2013-01-01 00:00:00
Time zone settings, I configured in the configuration file, the PRC is configured
Datetime::format is designed to be unaffected by external settings (object oriented)
So no matter how you change the environment parameter date_default_timezone, it will not affect the output result
To change the Datetime::format time zone setting, you need to
Datetime::settimezone Pass in a time zone object Datetimezone
Like what
$d = new DateTime (' @1356969600 '), $d->settimezone (New Datetimezone (' PRC ')), Echo $d->format (' y-m-d h:i:s ');
2013-01-01 00:00:00
Time zone problem ...
Look at my last paragraph.
Reference 5 Floor Helloyou0 's reply:
Date_default_timezone_set ("Europe/london");
$dt = new DateTime (' @1356969600 ');
echo $dt->gettimezone ()->getname (), "\ n";
echo $dt->format (' y-m-d h:i:s '), ...
You $dt = new DateTime (' @1356969600 '), in the @1356969600 timeline generated when the time is set, the conversion should be unified, otherwise you will have problems such as, when generated by: Date_default_ Timezone_set ("PRC"), the conversion page must also be used: Date_default_timezone_set ("PRC");