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

How to set time zone in php 5.6

藏色散人
Release: 2023-03-13 09:36:01
Original
2411 people have browsed it

How to set the time zone in php5.6: 1. Set the time zone to China through "date_default_timezone_set('prc');"; 2. Set the time zone in PHP.INI to "date.timezone = PRC" that is Can.

How to set time zone in php 5.6

The operating environment of this article: windows7 system, PHP version 5.6, DELL G3 computer

php 5.6 setting time zone

One:

//获取默认时区
echo date_default_timezone_get();
//将时区设置为中国
date_default_timezone_set('prc');
Copy after login

Two:

Set the time zone in PHP.INI

date.timezone = PRC
Copy after login

Set the time zone in the code

1 date_default_timezone_set('Asia/Shanghai');//'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');
Copy after login

Any of the above seven methods can meet our needs.

When the system is initialized, adding

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

will solve the problem of time zone difference of 8

hours.

Recommended learning: "PHP Video Tutorial"

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