Solution to the problem of date() warning reported by PHP program

jacklove
Release: 2023-03-27 15:14:01
Original
2187 people have browsed it

This article explains the solution to the date() warning reported by the PHP program.

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

Writing PHP Sometimes such warnings appear in the program:

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 getting this warning, you most likely misspelled the timezone identifier. We selected 'UTC' for '8.0/no DST' instead in D:\PHPWEB ews\file.php on line 17.

This is because the time taken by PHP is Greenwich Mean Time, so it will be different from your local time. The difference between Greenwich Mean Time and Beijing time is about 8 hours. We can follow the following Solution:

1. Use date_default_timezone_set() in the header to set my default time zone to Beijing time, that is,

<!--?php
    date_default_timezone_set("PRC");
?-->
Copy after login

.

2. Set the value of date.timezone in php.ini to PRC. After setting, it will be: date.timezone=PRC or date.timezone = Asia/Shanghai, and uncomment this line of code. That is, just remove the preceding semicolon.

Then restart apache!

This article explains the solution to the date() warning reported by the PHP program. For more related content, please pay attention to the PHP Chinese website.

Related recommendations:

How to solve the problem that the data queried by php is garbled and the Chinese code becomes Unicode when converting to json?

Explanation of PHP array traversal examples

Explanation of PHP array classification and array creation examples

The above is the detailed content of Solution to the problem of date() warning reported by PHP program. For more information, please follow other related articles on the PHP Chinese website!

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!