In php, if we do not configure the time zone when running the php date and time function, some time zone errors will be prompted. It is also possible that the time zone is incorrect and there are several hours related to Beijing time. Let me share these with you below. introduce.
When using PHP version 5.3 or above, as long as it involves time, one will be reported
I am using
echo date('Y-m-d');
?>
Tips
"PHP Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'UTC' for '8.0/no DST' instead in"
In fact, from PHP 5.1.0, when using functions such as date(), if the timezone is set incorrectly, E_NOTICE or E_WARNING information will be generated every time the time function is called. 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() in the header to set date_default_timezone_set('PRC'); //East Eighth Time Zone echo date('Y-m-d H:i:s');
2. Use ini_set('date.timezone','Asia/Shanghai');
in the header of the page3. Modify php.ini. Open php5.ini and search for date.timezone. Remove the semicolon and change it to: date.timezone =PRC