date_default_timezone_set not working.
my code:
ini_set['display_errors', true];
error_reporting[E_ALL];
date_default_timezone_set["UTC"];
echo date['Y-m-d H:i:s T'] . "
";
echo date['Y-m-d H:i:s T', time[]] . "
";
date_default_timezone_set["Asia/Shanghai"];
echo date['Y-m-d H:i:s T'] . "
";
echo date['Y-m-d H:i:s T', time[]] . "
";
ini_set["date.timezone","UTC"];
echo date['Y-m-d H:i:s T'] . "
";
echo date['Y-m-d H:i:s T', time[]] . "
";
ini_set["date.timezone","Asia/Shanghai"];
echo date['Y-m-d H:i:s T'] . "
";
echo date['Y-m-d H:i:s T', time[]] . "
";
all of them return the same date "2017-05-26 12:47:08 CST", why?
update:
I have fixed this problem, the reason is that I used the wrong way to change the timezone on CentOS7:
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
this way is right on CentOS6, but in CentOS7 /etc/localtime is linked to /usr/share/zoneinfo/Etc/UTC, so I damaged the UTC timezone.
the right way to change the timezone on CentOS7 is:
timedatectl set-timezone "Asia/Shanghai"
or
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
so I copied /usr/share/zoneinfo/Etc/UTC from other system to my system to fixed this problem.