Home >Backend Development >PHP Tutorial >Specific solutions to PHP Date() errors_PHP Tutorial

Specific solutions to PHP Date() errors_PHP Tutorial

WBOY
WBOYOriginal
2016-07-15 13:32:23720browse

When we used

to obtain the system time, we found that the obtained time did not match the system time. When I used echo date("Y-m-d H:i:s") to obtain the system time today, I found that the obtained time 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 PHP's time zone setting to Beijing time.

Specific solutions to PHP Date() errors:

Open the PHP.ini file, usually found in the PHP installation root directory
; date.timezone
Delete 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 the restart function of Apache. It is recommended to stop first and then restart start)
Recheck echo date("Y-m-d H:i:s").
Is the time back 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');

The functions date_default_timezone_set(timezone) and date_default_timezone_get()

The above are related solutions to PHP Date() errors.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446126.htmlTechArticleWhen we used to obtain the system time, we found that the obtained time did not match the system time. When I used echo date (Y-m-d H:i:s) to get the system time today, I found that the time obtained was different from the system time...
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