鍍金池/ 問答/PHP  iOS/ php DateTimeZone 設(shè)置UTC 無效

php DateTimeZone 設(shè)置UTC 無效

echo date_default_timezone_get();  // PRC
echo date("Y-m-d\TH:i:s\Z",time())  //2017-12-11T11:43:53Z

這段代碼和下邊代碼輸出時間一致

$now = new \DateTime();
$now->setTimezone(new \DateTimeZone('UTC'));
echo $now->format("Y-m-d\TH:i:s\Z"); //2017-12-11T11:43:53Z

那么 $now->setTimezone(new DateTimeZone('UTC')); 設(shè)置無效?

在線上服務(wù)器 運行是正常的 UTC時間差8小時。 在docker中運行輸出結(jié)果就一至。對比了php.ini 設(shè)置,都一致。

server1:

date/time support => enabled
"Olson" Timezone Database Version => 0.system
Timezone Database => internal
Default timezone => PRC

Directive => Local Value => Master Value
date.default_latitude => 31.7667 => 31.7667
date.default_longitude => 35.2333 => 35.2333
date.sunrise_zenith => 90.583333 => 90.583333
date.sunset_zenith => 90.583333 => 90.583333
date.timezone => PRC => PRC

server2:

date/time support => enabled
"Olson" Timezone Database Version => 0.system
Timezone Database => internal
Default timezone => PRC

Directive => Local Value => Master Value
date.default_latitude => 31.7667 => 31.7667
date.default_longitude => 35.2333 => 35.2333
date.sunrise_zenith => 90.583333 => 90.583333
date.sunset_zenith => 90.583333 => 90.583333
date.timezone => PRC => PRC

============ 補充,系統(tǒng)時間======

server1:

[root@60d882aec15f /]# timedatectl
Failed to create bus connection: No such file or directory
[root@60d882aec15f /]# date
Mon Dec 11 12:02:29 CST 2017
[root@60d882aec15f /]# date -u
Mon Dec 11 04:02:31 UTC 2017

server2:

[root@iZ8vbai4lhy4q1u5qhbenwZ ~]# timedatectl
Local time: Mon 2017-12-11 12:18:47 CST
Universal time: Mon 2017-12-11 04:18:47 UTC
RTC time: Mon 2017-12-11 12:18:47
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: no
NTP synchronized: yes
RTC in local TZ: yes
DST active: n/a
回答
編輯回答
刮刮樂

php.ini配置文件里面你修改了沒啊

2017年10月27日 09:08
編輯回答
故人嘆

樓主后來解決了么

我這邊也這樣
php.ini修改了 php-fpm / nginx都重啟了 還是差8個小時

2017年1月3日 19:39