How to set the time zone in php mysql

藏色散人
Release: 2023-03-12 17:24:01
Original
2554 people have browsed it

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.

How to set the time zone in php mysql

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 |
+——————+——–+
Copy after login

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'
Copy after login

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
Copy after login

For example

北京时间(GMT+0800)
set time_zone = '+8:00';
美国pst时间(GMT-08:00)
set time_zone = '-8:00';
Copy after login

SQL code

mysql> set time_zone = '+8:00';
Copy after login

Once the database is connected during program development, you can change the MySQL time immediately afterwards code.

mysql_query("SET time_zone = '+8:00'");
Copy after login

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!

Related labels:
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