The operation time of Beijing Metro Line 9 is a solution to the problem that the date function in PHP52 displays a time difference of 8 hours from Beijing time.

WBOY
Release: 2016-07-29 08:39:55
Original
1181 people have browsed it

Problem:

PHP function date("Y-n-d H-i-s"); The output time is 8 hours different from the local time.

Solution ideas

Beijing time is East 8th District, it may be a time zone issue. But there was no problem before After google, I found that starting from php5.1.0, the date.timezone option was added to php.ini. It is turned off by default, which means that the time displayed (no matter what php command is used) is Greenwich Mean Time. It is exactly 8 hours different from our time (Beijing time).

Set the time zone before calling the date() function.

Method 1:
date_default_timezone_set('PRC');
No return value. Now it’s OK to use the date function directly
$time = date(Y."Year".m."Month".d."Day".G."Hour".i."Min");

Method Two:

Modify;date.timezone = in php.ini to date.timezone = "Asia/Shanghai" (or change to date.timezone = PRC)and remove the semicolon in front,restart Apache.

The above introduces the solution to the problem that the date function in PHP52 displays an 8-hour difference from Beijing time when it comes to the operation time of Beijing Subway Line 9, including the operation time of Beijing Subway Line 9. I hope friends who are interested in PHP tutorials can learn from it. help.

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!