Home > Backend Development > PHP Tutorial > How to set timezone in php_PHP tutorial

How to set timezone in php_PHP tutorial

WBOY
Release: 2016-07-13 10:56:40
Original
1168 people have browsed it

If you are using an independent server and have permission to modify the configuration file, setting the time zone can be completed by modifying the date.timezone attribute in php.ini. We can set the value of this attribute to one of "Asia/Shang", "Asia/Chongqing", "Etc/GMT-8" or PRC, etc., and then the current time obtained in the PHP script is Beijing time . Modify the PHP configuration file as follows:

1.date.timezone = Etc/GMT-8
//Set the default time zone in the configuration file to East 8 (Beijing time)

Add one more sentence to the required php program:

The code is as follows Copy code
 代码如下 复制代码

date_default_timezone_set(‘PRC’);

date_default_timezone_set(‘PRC’);
 代码如下 复制代码

date_default_timezone_set(‘PRC’);
?>


If you want to test, you can write it like this:

?>
The code is as follows

Copy code
 代码如下 复制代码
date_default_timezone_set('Asia/Shanghai');//'Asia/Shanghai' 亚洲/上海
date_default_timezone_set('Asia/Chongqing');//其中Asia/Chongqing'为“亚洲/重庆”
date_default_timezone_set('PRC');//其中PRC为“中华人民共和国”
date_default_timezone_set(‘PRC’);

You can also open the php.ini file in the server and find; date.timezone. Remove the semicolon in front and change it to date.timezone=PRC (if you cannot find date.timezone in php.ini, you can directly add a line of date. timezone=PRC is also available). 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"
http://www.bkjia.com/PHPjc/632154.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632154.htmlTechArticleIf you are using an independent server and have permission to modify the configuration file, you can set the time zone by modifying php.ini The date.timezone property is completed. We can set the value of this attribute to...
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