On Windows , in the default PHP configuration, the time value returned by the DATE function is always 8 hours from the local time, that is, the GMT is displayed. The solution is to set the PHP time zone environment correctly. The time zone environment for PHP is specified by a specific set of strings. See the list of time zones supported by PHP. 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 ). If for some reason you cannot modify php.ini, you can use Date_default_timezone_set () settings in your PHP program. For example, you can do this 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.
The above is the PHP date time difference 8 hours of solution content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!
|