PHP date() function warning: It is not safe to rely on the system solution, safely_PHP tutorial

WBOY
Release: 2016-07-13 10:20:36
Original
811 people have browsed it

PHP date() function warning: It is not safe to rely on the system solution, safely

Recently, there are always system email prompts. I didn’t pay attention to it at first, but then I checked it after the prompts kept coming. Prompt the following information

Copy code The code is as follows:

PHP Warning: 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 gett
ing this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST' instead in /data0/htdocs/www.qttc.net/function/function.php on line 542

Generally speaking, the timezone is not set. In China, Green + 8 hours is used, so it needs to be set.

The first type

Add the following statement to the head of the page

Copy code The code is as follows:

date_default_timezone_set("PRC");

One disadvantage of this method is that all pages must be added

Second type

Find the date.timezone line in php.ini and change the value to PRC, such as date.timezone = PRC. If there is no such line, just add it directly. Finally, restart the WEB server and PHP.

PHP error prompt after phpinfo() check

Find date.timezone
in the php.ini file and set it to this date.timezone =Asia/Chongqing

When I use the date (Y-m-d H:i:s) function, the error message is as follows:

This is just a warning (Warning). Although it can be ignored, execution result errors may occur.
There is something wrong with the date (Y-m-d H:i:s) parameter you wrote. The correct way to write it is:
date('Y-m-d H:i:s',time()); //The following, time( ) can be omitted, but it is best to form a habit and write it in a more standardized way.

In addition, if you set the time zone (such as Shanghai, China, etc.), it will be more accurate.
For example, write this at the front of the file:
date_default_timezone_set('Asia/Shanghai'); //Set the time zone to "Asia/Shanghai", which is China.
echo date('Y-m-d H:i:s',time());
?>

Hope it helps!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/866664.htmlTechArticlePHP date() function warning: It is not safe to rely on the system solution, safelyly there are always The system email prompted me. I didn’t pay attention to it at first, but then I took a look at it after it kept reminding me. Tips start with...
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!