php Mysql time zone setting method: 1. Execute the "show variables like '%time_zone%';" command; 2. Set the time zone by modifying the mysql configuration file my.cnf or my.ini; 3. Through The "set time_zone" command sets the time zone.
The operating environment of this article: Windows7 system, PHP7.1 version, Dell G3 computer
php How to set the time zone of mysql?
MySQL time zone setting method
MySQL time zone defaults to the server's time zone, which is 8 hours different from China's time zone.
View method
SQL code
mysql> show variables like '%time_zone%';
+——————+——–+ | Variable_name | Value | +——————+——–+ | system_time_zone | CST | | time_zone | SYSTEM | +——————+——–+
Modify time zone method
Method 1:
You can modify the time zone by modifying the mysql configuration file my.cnf or my.ini
Add default-time-zone=timezone under [mysqld] .
For example:
default-time-zone = '+8:00'
Restart msyql
Be sure to add it under [mysqld], otherwise unknown variable 'default-time-zone= 8:00' will appear
Method 2:
通过命令 set time_zone = timezone
For example
北京时间(GMT+0800) set time_zone = '+8:00'; 美国pst时间(GMT-08:00) set time_zone = '-8:00';
SQL code
mysql> set time_zone = '+8:00';
Once the database is connected during program development, you can change the MySQL time immediately afterwards code.
mysql_query("SET time_zone = '+8:00'");
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to set the time zone in php mysql. For more information, please follow other related articles on the PHP Chinese website!