Warning: date() [function.date]: It is not safe to rely on

今天在学习php的时候,用date()函数的时候出现了一个问题,原本是要出现:

Bob’s Auto Parts

Order Results

Order processed. at22:10, 23rd March 2011

Your order is as follows:

tires

bottles of oil

spark plugs

的页面居然显示:

Bob’s Auto Parts

Order Results

Warning: date() [function.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

E:\www\processorder.php on line 15

Order processed. at14:09, 23rd March 2011

Your order is as follows:

tires

bottles of oil

spark plugs

发现时间比我们少了8小时,初步判断是默认的格林尼治时间,网上很多论坛都有解决方法,一般都是两种:

1、在页头使用date_default_timezone_set()设置默认时区为北京时间,即

date_default_timezone_set("PRC");

就可以了。

2、在php.ini中设置date.timezone的值为PRC,设置好以后的为:date.timezone=PRC,同时取消这一行代码的注释,即去掉前面的分号就可以了。

我试过第一种方法,是可行了,而第二种方法修改了之后,然后关闭阿帕奇,却依然不行。我想将来如果还是遇到这种情况,我只能使用第一种方法了。

Tonitech版权所有 | 转载请注明出处: http://www.tonitech.com/?p=405