Home > Article > Backend Development > How to set time zone in php 5.6
How to set the time zone in php5.6: 1. Set the time zone to China through "date_default_timezone_set('prc');"; 2. Set the time zone in PHP.INI to "date.timezone = PRC" that is Can.
The operating environment of this article: windows7 system, PHP version 5.6, DELL G3 computer
php 5.6 setting time zone
One:
//获取默认时区 echo date_default_timezone_get(); //将时区设置为中国 date_default_timezone_set('prc');
Two:
Set the time zone in PHP.INI
date.timezone = PRC
Set the time zone in the code
1 date_default_timezone_set('Asia/Shanghai');//'Asia/Shanghai' 亚洲/上海 2 date_default_timezone_set('Asia/Chongqing');//其中Asia/Chongqing'为“亚洲/重庆” 3 date_default_timezone_set('PRC');//其中PRC为“中华人民共和国” 4i ni_set('date.timezone','Etc/GMT-8'); 5 ini_set('date.timezone','PRC'); 6 ini_set('date.timezone','Asia/Shanghai'); 7 ini_set('date.timezone','Asia/Chongqing');
Any of the above seven methods can meet our needs.
When the system is initialized, adding
ini_set('date.timezone','Asia/Shanghai'); 或 date_default_timezone_set("PRC");
will solve the problem of time zone difference of 8
hours.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to set time zone in php 5.6. For more information, please follow other related articles on the PHP Chinese website!