Home > Backend Development > PHP Tutorial > Correctly interpret the causes of PHP time acquisition errors_PHP Tutorial

Correctly interpret the causes of PHP time acquisition errors_PHP Tutorial

WBOY
Release: 2016-07-15 13:34:15
Original
997 people have browsed it

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.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445999.htmlTechArticleWhen we use echo date (Y-m-d H:i:s) to obtain the system time today, we found that the obtained The time does not match the system time. PHP was developed by foreigners, so there are often many things that are not quite right...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template