When we used
to get the system time using echo date ("Y-m-d H:i:s") today, we found that the time obtained did not match the system time. .
PHP was developed by foreigners, so there are often many things that are not easy to use. After some research, I found that the default time set by PHP is based on Greenwich Time Zone, which is 8 hours different from Beijing time, so we need to increase it by 8 hours. The principle is that we are exactly in the East 8th District of the time zone. , so we must change the PHP time zone setting to Beijing time.
Solution to PHP time acquisition error:
Open the PHP.ini file, usually in the PHP installation root directory, find the ;date.timezone and delete it Remove the semicolon in front of date.timezone and change it to date.timezone = PRC. Save and restart the Apahce service (sometimes there will be problems with Apache's restart function, it is recommended to stop first and then start)
Recheck the echo date ("Y-m-d H:i:s"). Is it time to return to normal?
If you cannot change the PHP.ini file, you can also use date_default_timezone_set() to set the time zone before outputting the time
date_default_timezone_set('Asia/Shanghai');
Function
date_default_timezone_set(timezone) and date_default_timezone_get()
The problem of PHP getting the wrong time seems simple, but it cannot be ignored. I hope everyone can pay attention to these small flaws in future programming.