Home > Backend Development > PHP Tutorial > php date() time function reports error, time zone problem solved UTC PRC CST_PHP tutorial

php date() time function reports error, time zone problem solved UTC PRC CST_PHP tutorial

WBOY
Release: 2016-07-13 10:57:41
Original
1724 people have browsed it

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 page

3. Modify php.ini. Open php5.ini and search for date.timezone. Remove the semicolon and change it to: date.timezone =PRC

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632072.htmlTechArticleIn php, if we do not configure the time zone when running the php date and time function, some time zone errors will be prompted. There may also be a time zone error, which is related to Beijing time for several hours...
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