After obtaining the time through the date () function, it is found that the hour time is incorrect, which is 8 hours less than the current time. Both H and h are the same, this is because the Greenwich Mean Time is obtained, which is 8 hours different from Beijing time.
The solution is as follows:
:
1. Modify the php. ini configuration file.
Open the php. Ini file. Generally, find the; date. timezone in the root directory of the php configuration. Delete the semicolon and change it to date timezone = PRC. Save and restart the Apahce service (sometimes there is a problem with restart, stop first and then start ).
2. Add the date_default_timezone_set (timezone_identifier) function
This function sets the current time zone, initializes the time, and adds this sentence before the page header or get the time statement.
For example:
Date_default_timezone_set (PRC );
Echo date ("Y-m-d H-I-s ");
The parameters are as follows:
Date_default_timezone_set (PRC)-set to Beijing time. PRC represents the People's Republic of China.
Date_default_timezone_set ('Asia/Shanghai')-set to Shanghai time. Available options include 'chungqi '(Chongqing) and 'Urumqi' (Urumqi).
Available in Hong Kong and Taiwan regions: Asia/Macao, Asia/Hong_Kong, Asia/Taipei (in the order of Macao, Hong Kong, and Taipei)
Singapore: Asia/Singapore (it seems that Beijing is not seen)
This function always returns True, but you must enter timezone_identifier. Otherwise, an error is returned.
The following are all the time zone identifiers: (for your reference)
CET
CST6CDT
Cuba
EET
Egypt
Eire
EST
EST5EDT
Etc/GMT
Etc/GMT + 0
Etc/GMT + 1
Etc/GMT + 10
Etc/GMT + 11
Etc/GMT + 12
Etc/GMT + 2
Etc/GMT + 3
Etc/GMT + 4
Etc/GMT + 5
Etc/GMT + 6
Etc/GMT + 7
Etc/GMT + 8
Etc/GMT + 9
Etc/GMT-0
Etc/GMT-1
Etc/GMT-10
Etc/GMT-11
Etc/GMT-12
Etc/GMT-13
Etc/GMT-14
Etc/GMT-2
Etc/GMT-3
Etc/GMT-4
Etc/GMT-5
Etc/GMT-6
Etc/GMT-7
Etc/GMT-8
Etc/GMT-9
Etc/GMT0
Etc/Greenwich
Etc/UCT
Etc/Universal
Etc/UTC
Etc/Zulu
Factory
GB
GB-Eire
GMT
GMT + 0
GMT-0
GMT0
Greenwich
Hongkong
HST
Iceland
Israel
Jamaica
Japan
Kwajalein
Libya
MET
MST
MST7MDT
Navajo
NZ
NZ-CHAT
Poland
Portugal
PRC
PST8PDT
ROC
ROK
Singapore
Turkey
UCT
Universal
UTC
W-SU
WET