[服务器时区问题]PHP Warning: strftime(): It is not safe to rely on the system's timezone set PHP Warning: strftime(): It is not safe to rely on the system's timezone set

PHP Warning: strftime(): It is not safe to rely on the system's timezone set

When running some programs, there are warning logs like this in the httpd log:

PHP Warning:  strftime(): 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 'Asia/Chongqing' for 'CST/8.0/no DST'。。。。。。。。。。。

 

 

  • Reason analysis:
      This is because PHP defaults to Greenwich Mean Time (UTC) for time conversion, because the local time you are in will be different from UTC, and there is an 8-hour difference between Greenwich Mean Time and Beijing Time. Time difference. So we have to specify a time zone for PHP and let PHP know which time zone to convert to.

  • Solution:

  1.       Use date_default_timezone_set() in the header of your PHP program to set my default time zone to Beijing time (PRC, Chinese abbreviation), that is, <?php date_default_timezone_set("PRC"); ?>. This method is too complicated to use, and related functions must be added to each file that uses date. The following method is simpler and more convenient.

  2. Find the date.timezone line in php.ini, support the preceding ';' (if it has not been modified, this option should not be enabled), and set its value to PRC, after setting it is: date.timezone ="Asia/Shanghai".

 
This problem is currently solved with the 2nd method

When running some programs, there are warning logs like this in the httpd log:

PHP Warning:  strftime(): 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 'Asia/Chongqing' for 'CST/8.0/no DST'。。。。。。。。。。。

 

 

  • Reason analysis:
      This is because PHP defaults to Greenwich Mean Time (UTC) for time conversion, because the local time you are in will be different from UTC, and there is an 8-hour difference between Greenwich Mean Time and Beijing Time. Time difference. So we have to specify a time zone for PHP and let PHP know which time zone to convert to.

  • Solution:

  1.       Use date_default_timezone_set() in the header of your PHP program to set my default time zone to Beijing time (PRC, Chinese abbreviation), that is, <?php date_default_timezone_set("PRC"); ?>. This method is too complicated to use, and related functions must be added to each file that uses date. The following method is simpler and more convenient.

  2. Find the date.timezone line in php.ini, support the preceding ';' (if it has not been modified, this option should not be enabled), and set its value to PRC, after setting it is: date.timezone ="Asia/Shanghai".

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324930441&siteId=291194637