There are many ways to set the time in php. The most commonly used method is to modify date.timezone directly in php.ini. If you do not have server permissions, you can directly use the date_default_timezone_set function to set it. I will introduce it to you below.
Can modify php.ini. Open php.ini and search for date.timezone. Remove the semicolon = and add XXX after it. Restart the http service (such as apache2 or iis, etc.)
Regarding XXX, the available values in mainland China are: Asia/Chongqing, Asia/Shanghai, Asia/Urumqi (in order, Chongqing, Shanghai, and Urumqi
Set time zone in php.ini
The code is as follows
代码如下 |
复制代码 |
date.timezone = PRC
|
|
Copy code
|
代码如下 |
复制代码 |
date_default_timezone_set('Asia/Shanghai');//'Asia/Shanghai' 亚洲/上海
date_default_timezone_set('Asia/Chongqing');//其中Asia/Chongqing'为“亚洲/重庆”
date_default_timezone_set('PRC');//其中PRC为“中华人民共和国”
ini_set('date.timezone','Etc/GMT-8');
ini_set('date.timezone','PRC');
ini_set('date.timezone','Asia/Shanghai');
ini_set('date.timezont','Asia/Chongqing');
|
date.timezone = PRC
代码如下 |
复制代码 |
date_default_timezone_set('PRC');
测试:
echo date('Y-m-d H:i:s');
|
|
Set time zone in code
The code is as follows
|
Copy code
date_default_timezone_set('Asia/Shanghai');//'Asia/Shanghai' Asia/Shanghai
date_default_timezone_set('Asia/Chongqing');//Asia/Chongqing' is "Asia/Chongqing"
date_default_timezone_set('PRC');//where PRC is "People's Republic of China"
ini_set('date.timezone','Etc/GMT-8');
ini_set('date.timezone','PRC');
ini_set('date.timezone','Asia/Shanghai');
ini_set('date.timezont','Asia/Chongqing');
We can set the above code directly in the PHP page header.
The code is as follows
|
Copy code
|
date_default_timezone_set('PRC');
Test:
echo date('Y-m-d H:i:s');
http://www.bkjia.com/PHPjc/632126.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632126.htmlTechArticleThere are many ways to set the time in php, the most commonly used one is to do it directly in php.ini Date.timezone has been modified. If you do not have server permissions, you can use date_default_t directly...
|
|
|
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