Home  >  Article  >  Backend Development  >  How to set timezone in php

How to set timezone in php

藏色散人
藏色散人Original
2020-08-10 10:09:373152browse

How to set timezone in php: 1. Set "date.timezone="Asia/Shanghai"" in "php.ini"; 2. Add "date_default_timezone_set("PRC");" to the page; 3. , add setting time zone in the header of the page.

How to set timezone in php

Recommended: "PHP Video Tutorial"

Three types of time zone settings in PHP Method

Method 1:

(The best method) Add the date.timezone item found in php.ini, set date.timezone = "Asia/Shanghai", and restart the environment It’s ok.

Method 2:

When you need to use these time functions, add date_default_timezone_set("PRC");

Method 3:

Add the setting time zone ini_set('date.timezone','Asia/Shanghai');

to the header of the page. In summary, method one and method three generally require server permissions to be more effective. , and method 2 technicians can control the current page, which is also a commonly used method by programmers.

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