Home >Backend Development >PHP Tutorial >How to set 8-hour difference in PHP system time zone_PHP tutorial
php tutorial system time zone 8 hour difference setting method
Two ways to modify the PHP system time zone:
1. Modify the settings in the php.ini file, find ";date.timezone=" under [date], change the item to date.timezone=asia/hong_kong (prc China time), and then restart the apache server.
2. In the application, add the "date_default_timezone_set("asia/hong_kong")" function before using the time and date function
Get the local time after modifying the php.ini file:
php code:
echo "It is Beijing time now:".date("y-m-d h:i:s")."
";
?>
Display results:
Now is Beijing time: 2010-11-30 20:50:03 (consistent with local time)
php.ini modified code:
[date]
; defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = prc
See more methods below
1. Modify the settings in the php.ini file.
[date]
//defines the default timezone used by the date functions
date.timezone = asia/shanghai
It's true here. . . You can set shanghai, chongqin, hong_kong, taibei... and so on, but beijing is not found. I don't know why.
2. Set when running in php program.
If(date_default_timezone_get() != "1asia/shanghai") date_default_timezone_set("asia/shanghai");
?>
Note: There is a 1 in the time setting obtained using "date_default_timezone_get". I don't know if it is a miscellaneous thing.
3. It’s okay to add 8*3600 seconds when using the time.
echo date("y-m-d h:i:s",time()+8*3600);
?>
Note:
Since php5.0, when using php to get the system time, the time is 8 hours less than the current time. The reason is that when timezone is not set in php.ini, php uses UTC time, so the time in China is 8 hours less