Home > Backend Development > PHP Tutorial > Solve the problem of 'It is not safe to rely on the system's timezone settings” in PHP

Solve the problem of 'It is not safe to rely on the system's timezone settings” in PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 09:02:03
Original
867 people have browsed it

This article mainly introduces the method to solve the problem of "It is not safe to rely on the system's timezone settings" in PHP. Friends who need it can refer to it

If you use PHP5.3 or above, if there is no correct configuration An error with the PHP date function will appear in php.ini. Many old PHP programming tutorials did not mention this problem in the past, so many readers will feel confused. The author below will tell you three methods to solve this problem.
"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"

Actually, from PHP 5.1 .0, when using functions such as date(), if the timezone setting is incorrect, E_NOTICE or E_WARNING information will be generated every time the time function is called. And in PHP 5.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 PHP 5.3, it seems that this will be forcibly thrown out if it is not set. Wrong, to solve this problem, just localize it.

1. Use date_default_timezone_set() in the header to set date_default_timezone_set('PRC'); //Eastern Eighth Time Zone echo
date('Y-m-d H:i:s');

2. Use ini_set('date.timezone','Asia/Shanghai');

3. Modify php.ini (if it is a windows system, Then the file is in the C drive, Windows directory, if the system is installed on the C drive). Use notepad to open php.ini, search for date.timezone, remove the semicolon in front and change it to: date.timezone = "Asia/Shanghai"
Restart php or http service (such as apache2 or iis, etc.) and that's it!

You can choose any one of the above three methods. The editor recommends using the third method without adding extra code every time.


The above has introduced how to solve the “It is not safe to rely on the system’s timezone settings” problem in PHP, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

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