Home >Backend Development >PHP Tutorial >How to solve the 8-hour time difference problem in php

How to solve the 8-hour time difference problem in php

怪我咯
怪我咯Original
2017-07-07 09:29:461619browse

I discovered a problem a few days agodate("Y-m-d G:i T",time()) The time taken out is always different from the local time It took 8 hours, but my system was clearly in China Standard Time (GMT+8), and I finally found the problem.

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.

That is, the displayed time (no matter what php command is used) The difference between Greenwich Mean Time

and our time (Beijing time) is exactly 8 hours. There are three methods below to restore the normal time.

1, the simplest way is not to use php5.1 or above version

2, if you must use it, and you cannot modify php.ini, you need to initialize the time statement Add
date_default_timezone_set (XXX);
3 to the
, 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 below GMT-8 that I compiled from the official php manual file. There may be some omissions

The above is the detailed content of How to solve the 8-hour time difference problem in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn