Home >Backend Development >PHP Tutorial >Summary of solutions to the 8-hour time difference in PHP_PHP tutorial
It turns out that starting from php5.1.0, the date.timezone option has been added to php.ini. It is turned off by default
, which means that the time displayed (no matter what php command is used) is Greenwich Mean Time
There is a difference of exactly 8 hours from our time (Beijing time). There are 3 methods below to restore the normal time.
1. The simplest way is not to use php5.1 or above.
2. If you must use it and cannot modify php.ini, you need to initialize the time statement. Add date_default_timezone_set (XXX);
3 to
, once and for all, only php.ini can be modified. Open php.ini and search for date.timezone. Remove the semicolon in front
= and add XXX after it. Restart the http service (such as apache2 or iis, etc.)
Regarding XXX, the values available in mainland China Are: Asia/Chongqing, Asia/Shanghai, Asia/Urumqi (in order Chongqing, Shanghai, Urumqi)
Available in Hong Kong and Taiwan: Asia/Macao, Asia/Hong_Kong, Asia/Taipei (in order Macau, Hong Kong, Taipei)
And Singapore: Asia/Singapore
Foreigners seem to have missed Beijing
Other available values are: Etc/GMT-8, Singapore, Hongkong, PRC
What is PRC? PRC is the People's Republic of China -_-
The above are the regions under GMT-8 that I compiled from the official php manual file. There may be some omissions.