Home >Backend Development >PHP Tutorial >php prompt PHP Warning: date(): It is not safe to rely on the... Error solution_PHP tutorial
Sometimes such a warning will appear when writing PHP programs:
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...
This is because the default time obtained by PHP is Greenwich Mean Time, so this time will be 8 hours different from standard Beijing time. We can use the following method to solve this problem:
1. Use date_default_timezone_set('PRC') in the header to set the time zone to Beijing time.
For the specific time zone list, please refer to: Solution to the 8-hour difference in date time in php
2. Set the value of date.timezone to PRC in the server configuration file php.ini. After setting it, it will be: date.timezone=PRC. At the same time, remove the preceding semicolon, that is, uncomment this line of code.
Tips: date_timezone_set — alias DateTime::setTimezone()