Home  >  Article  >  Backend Development  >  How to remove the warning when getting the current date in php

How to remove the warning when getting the current date in php

王林
王林Original
2021-10-13 16:15:461367browse

php method to remove the warning when getting the current date: 1. Set the value of date.timezone to PRC in php.ini; 2. Cancel the comment before date.timezone=PRC code; 3. Restart apache .

How to remove the warning when getting the current date in php

The operating environment of this article: windows10 system, php 7, thinkpad t480 computer.

When getting the current date, a warning similar to the following may be generated:

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 is not the same as yours Local times may vary. The difference between Greenwich Mean Time and Beijing time is about 8 hours. We can solve it according to the following methods:

1. Use date_default_timezone_set() on the header of the page to set my default time zone to Beijing time.

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.

Recommended learning: php training

The above is the detailed content of How to remove the warning when getting the current date in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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