search
HomeBackend DevelopmentPHP ProblemHow to set the time zone in php mysql

How to set the time zone in php mysql

Sep 18, 2021 am 09:49 AM
mysqlphpTime zone

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 |
+——————+——–+

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!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor