Home  >  Article  >  Backend Development  >  Solution to the problem that the date() function in PHP5.2 displays a time difference of 8 hours from Beijing time_PHP Tutorial

Solution to the problem that the date() function in PHP5.2 displays a time difference of 8 hours from Beijing time_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 15:46:371136browse

Question:

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 in the East 8th District, which may be a time zone issue. But it was no problem before. After searching through Google, I found that starting from php5.1.0, the date.timezone option was added to php.ini, which is turned off by default. , that is, the time displayed (no matter what php command is used) is Greenwich Mean Time, which 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. It’s OK to use the date function directly below
$time = date(Y."Year".m."Month".d."Day".G."Hour".i."Min");

Method 2:

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320078.htmlTechArticleProblem: The php function date("Y-n-d H-i-s"); output time is 8 hours different from the local time. Solution The idea is that Beijing time is in the East 8th District, which may be a time zone issue. But there was no problem before. After go...
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