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!