Home > Backend Development > PHP Problem > How to set time zone in linux php

How to set time zone in linux php

藏色散人
Release: 2023-03-04 08:50:01
Original
2566 people have browsed it

Linux PHP time zone setting method: first execute the command "cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime"; then set the time zone in PHP to "Asia/Shanghai"; finally Just restart the system.

How to set time zone in linux php

Recommended: "PHP Video Tutorial"

Linux setting time zone, taking CentOS5.5 as an example:

The code is as follows

cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
Copy after login

Set the time zone in MySQL

Edit the MySQL configuration file: my.cnf/my.ini, add under [mysqld]:

The code is as follows

default-time-zone = '+8:00'
Copy after login

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.

Recommended: "linux tutorial"

Set the time zone in PHP

In the PHP configuration file PHP.ini:

The code is as follows

date.timezone = "Asia/Shanghai"
Copy after login

After setting up, it is best to restart the system.

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

 ini_set('date.timezone', 'Asia/Shanghai'); 
 date_default_timezone_set('Asia/Shanghai');
Copy after login

The above is the detailed content of How to set time zone in linux php. 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