PHP Warning: date(): It is not safe to rely on the system

昨天碰到使用date()函数时出现PHP Warning: date(): It is not safe to rely on the system出现这种错误是因为php5默认date.timezone为utc,改为date.timezone = PRC即可.下面看我的方法总结。

在php程序中运行时报如下警告信息:

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

主要是时区没有设置的缘故,调整很简单,打开php.ini文件,并找到date.timezone这行,改成如下:date.timezone = Asia/Shanghai,然后重启apache即可!

在php程序中解决,在你程序前加上如下代码:

date_default_timezone_set('asia/shanghai');或者

ini_set('date.timezone','asiashanghai');