PHP Program Time difference 8 hours solution
In a PHP environment that uses a foreign host or a locally configured installation, the default setting is the foreign time zone or the default time zone of the system. The time value returned by the DATE function is always 8 hours apart from the local time in Beijing.
The solution is to properly configure the PHP time zone environment.
The time zone environment for PHP is specified by a specific set of strings. The easiest way is to find the Date.timezone line in the php.ini file, which is commented out by default, and can be enabled by deleting the previous semicolon. For mainland China, it can be set to etc/gmt-8 (or Asia/sanghai, asia/chongqing, Asia/urumqi, PRC). Then restart the Web server.
If for some reason the php.ini cannot be modified, it can be set at the beginning of the PHP program with Date_default_timezone_set (). For example, you can execute code before using the DATE function
Date_default_timezone_set (' etc/gmt-8 ');
I personally think it is better to use the Date_default_timezone_set function. One is the versatility, and secondly, if your site is for global users, this method allows each user to set his time zone.
Finally, it is necessary to illustrate the wording of ETC/GMT. China is using the East eight region of the time, under normal circumstances are recorded as +8, but PHP has come a big anti-height, to write etc/gmt-8; Conversely, if your time zone is the West 2 zone, in PHP will be written etc/gmt+2. This is different from common sense, especially to note.