date_default_timezone_set('asia/shanghai');
//echo date_default_timezone_get();
//echo date('Y-m-d H:i:s',time());
echo date_default_timezone_get(); // asia/shanghai
$time = time();
$timezone = new DateTimeZone('Asia/Shanghai');
$date = new DateTime('@'.$time, $timezone);
var_dump($timezone->getLocation());// Beijing Time
echo $date->format('Y-m-d H:i:s');// 2017-01-11 12:32:20
echo '<br />';
echo date('Y-m-d H:i:s',$time);// 2017-01-11 20:32:20
输出:
asia/shanghai
array(4) {
["country_code"]=>
string(2) "CN"
["latitude"]=>
float(31.23333)
["longitude"]=>
float(121.46666)
["comments"]=>
string(12) "Beijing Time"
}
2017-01-11 12:32:20
2017-01-11 20:32:20
文档链接