Home > Article > Backend Development > Summary of Linux php time zone setting method_PHP tutorial
The default time zone in PHP is 8 hours related to China. Now I will introduce to you how to solve the 8-hour PHP time difference between Linux and Windows systems. I hope it will be helpful to all students.
The available values in mainland China are: Asia/Chongqing, Asia/Shanghai, Asia/Urumqi (in order Chongqing, Shanghai, Urumqi)
Available in Hong Kong and Taiwan: Asia/Macao, Asia/Hong_Kong, Asia/Taipei (Macau, Hong Kong, Taipei in order)
And Singapore: Asia/Singapore
Other available values are: Etc/GMT-8, Singapore, Hongkong, PRC
1. Set the time zone in Linux, taking CentOS5.5 as an example:
The code is as follows | Copy code | ||||
|
Edit the MySQL configuration file: my.cnf/my.ini, add:
代码如下 | 复制代码 |
default-time-zone = '+8:00' |
The code is as follows | Copy code |
default-time-zone = '+8:00' |
In fact, if the time zone of the OS where MySQL is located has been set correctly, you do not need to set the time zone in MySQL, because when the MySQL service starts, it will automatically adopt the time zone of the OS.
3. Set time zone in PHP
代码如下 | 复制代码 |
date.timezone = "Asia/Shanghai" |
The code is as follows | Copy code |
date.timezone = "Asia/Shanghai"
|
代码如下 | 复制代码 |
ini_set('date.timezone', 'Asia/Shanghai'); date_default_timezone_set('Asia/Shanghai'); |
If you purchased the web space, you do not have permission to configure the time zone in Linux PHP MySQL. That's easy to do, you just need to set the time zone corresponding to the OS in the PHP script, because MySQL uses the OS time zone by default. Assuming that the time zone of the OS is 'Asia/Shanghai', use one of the following two statements:
The code is as follows | Copy code | ||||
ini_set('date.timezone', 'Asia/Shanghai');
date_default_timezone_set('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'); |
The code is as follows | Copy code |
date.timezone = PRC |
The code is as follows | Copy code |
1 date_default_timezone_set('Asia/Shanghai');//'Asia/Shanghai' Asia/Shanghai 2 date_default_timezone_set('Asia/Chongqing');//Asia/Chongqing' is "Asia/Chongqing" 3 date_default_timezone_set('PRC');//where PRC is "People's Republic of China" 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 initializing the system, add
The code is as follows
|
Copy code
|
||||
ini_set('date.timezone','Asia/Shanghai'); |
http: //www.bkjia.com/PHPjc/632744.html