先看正常场景:
$now = time();
echo "Now: {$now}",PHP_EOL;
date_default_timezone_set("Etc/GMT-8");
echo "Etc/GMT-8: ",date("Y-m-d H:i:s", $now),PHP_EOL;
date_default_timezone_set("Asia/Shanghai");
echo "Asia/Shanghai: ",date("Y-m-d H:i:s", $now),PHP_EOL;
echo "Now: {$now}",PHP_EOL;
date_default_timezone_set("Etc/GMT-8");
echo "Etc/GMT-8: ",date("Y-m-d H:i:s", $now),PHP_EOL;
date_default_timezone_set("Asia/Shanghai");
echo "Asia/Shanghai: ",date("Y-m-d H:i:s", $now),PHP_EOL;
输出:
Now: 1670922643
Etc/GMT-8: 2022-12-13 17:10:43
Asia/Shanghai: 2022-12-13 17:10:43
Etc/GMT-8: 2022-12-13 17:10:43
Asia/Shanghai: 2022-12-13 17:10:43
再看不正常的场景
$now = 641314800;
echo "Now: {$now}",PHP_EOL;
date_default_timezone_set("Etc/GMT-8");
echo "Etc/GMT-8: ",date("Y-m-d H:i:s", $now),PHP_EOL;
date_default_timezone_set("Asia/Shanghai");
echo "Asia/Shanghai: ",date("Y-m-d H:i:s", $now),PHP_EOL;
echo "Now: {$now}",PHP_EOL;
date_default_timezone_set("Etc/GMT-8");
echo "Etc/GMT-8: ",date("Y-m-d H:i:s", $now),PHP_EOL;
date_default_timezone_set("Asia/Shanghai");
echo "Asia/Shanghai: ",date("Y-m-d H:i:s", $now),PHP_EOL;
输出,可以看到上海时间快了一个小小时
Now: 641314800
Etc/GMT-8: 1990-04-28 23:00:00
Asia/Shanghai: 1990-04-29 00:00:00
Etc/GMT-8: 1990-04-28 23:00:00
Asia/Shanghai: 1990-04-29 00:00:00
结论
在某个时间区间,Etc/GMT-8慢一个小时,参考:https://zh.wikipedia.org/wiki/%E4%B8%AD%E5%9C%8B%E6%99%82%E5%8D%80#%E5%A4%8F%E6%99%82%E5%88%B6
当前还没有任何评论