PHP 8 hour time difference solution summary

  • 2020-03-31 19:59:15
  • OfStack

Since PHP 5.1.0, php.ini has added date.timezone, which is off by default

So the time displayed (whatever PHP command you use) is Greenwich mean time, right

It's exactly 8 hours behind our time (Beijing time). Here are 3 ways to get back to normal.

1. The easiest way to do this is to not use php5.1 or above

2, if must be used, and cannot modify php.ini, then need in the statement about the time of the initialization
Date_default_timezone_set (XXX);

3. Once and for all, only php.ini can be modified. Open php.ini to look for date.timezone and remove the semicolon
= followed by XXX, restart the HTTP service (such as apache2 or iis) can be


For XXX, the available values for the mainland are: Asia/Chongqing, Asia/Shanghai, Asia/Urumqi (Chongqing, Shanghai, Urumqi, in order)
Available for hong Kong and Taiwan: Asia/Macao, Asia/hong Kong Kong, Asia/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
These are the areas below gmt-8 that I've compiled from the official PHP documentation, which may be missing

Related articles: