Home > Backend Development > PHP Tutorial > Various solutions to the time difference of 8 hours in PHP_PHP Tutorial

Various solutions to the time difference of 8 hours in PHP_PHP Tutorial

WBOY
Release: 2016-07-13 10:55:38
Original
1054 people have browsed it

There are two ways to solve the 8 hours related to time zone. One is to write date.timezone = PRC in php.ini, and the other is to write date_default_timezone_set('Asia/Chongqing'); in the php code. .

After php5, you have to set the time zone yourself, either by modifying the settings of php.ini or modifying it in the code.

Set time zone in PHP.INI

 代码如下 复制代码
date.timezone = PRC

Set time zone in code

 代码如下 复制代码
date_default_timezone_set('PRC');//其中PRC为“中华人民共和国”

The above can meet our needs.

When initializing the system, add

The code is as follows
 代码如下 复制代码
ini_set('date.timezone','Asia/Shanghai');
  或
date_default_timezone_set("PRC"); 
Copy code


ini_set('date.timezone','Asia /Shanghai'); or

date_default_timezone_set("PRC");

 代码如下 复制代码
date_default_timezone_set('Asia/Chongqing');
echo date('Y-m-d H:i:s');
?>


You can also write it like this in php
The code is as follows Copy code

date_default_timezone_set('Asia/Chongqing'); echo date('Y-m-d H:i:s'); ?> If you use the first method, remember to restart your apahce server. If you use the second method, it doesn’t matter. Now let’s solve the time zone difference of 8
http://www.bkjia.com/PHPjc/632218.html
www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632218.htmlTechArticleThere are two ways to solve the time zone related 8 hours. One is to put date.timezone = in php.ini PRC is written like this, one is date_default_timezone_set('Asia/Chongqing'); in the php code, so...
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