Home > Backend Development > PHP Tutorial > Example of setting method for changing time and time zone in PHP

Example of setting method for changing time and time zone in PHP

小云云
Release: 2023-03-20 19:34:01
Original
1366 people have browsed it


In fact, from PHP 5.1.0, when using functions such as date(), if the timezone is set incorrectly, E_NOTICE or E_WARNING will be generated every time the time function is called. information. And in php5.1.0, the date.timezone option is turned off by default. No matter what php command is used, it is Greenwich Mean Time. However, in PHP5.3, it seems that this will be forcibly thrown out if it is not set. Wrong, to solve this problem, just localize it.
The following are three methods (any one will work):
1. Use date_default_timezone_set() on the header of the page to set date_default_timezone_set('PRC'); //East Eight time zone echo date('Y-m-d H:i :s');
2. Use ini_set('date.timezone','Asia/Shanghai');
3. Modify php.ini in the header. Open php5.ini and search for date.timezone. Remove the semicolon and change it to: date.timezone =PRC
Restart the http service (such as apache2 or iis, etc.).

Related recommendations:

php time format processing method

##Summary of common php time function usage

Summary of php time zone setting method

The above is the detailed content of Example of setting method for changing time and time zone in 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