《PHP應(yīng)用:解決php的“It is not safe to rely on the system’s timezone settings”問題》要點(diǎn):
本文介紹了PHP應(yīng)用:解決php的“It is not safe to rely on the system’s timezone settings”問題,希望對您有用。如果有疑問,可以聯(lián)系我們。
PHP編程如果使用PHP5.3以上版本時,如果沒有正確的配置php.ini就會出現(xiàn)PHP日期函數(shù)的錯誤.以前很多舊的PHP編程教程沒有說到這個問題,所以不少讀者會覺得困惑,下面筆者為大家講述解決這個問題的三種辦法.
"PHP 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"
PHP編程實際上,從PHP 5.1.0,當(dāng)對使用date() 等函數(shù)時,如果 timezone 設(shè)置不正確,在每一次調(diào)用時間函數(shù)時,都會產(chǎn)生 E_NOTICE 或者 E_WARNING 信息.而又在 PHP 5.1.0 中,date.timezone 這個選項,默認(rèn)情況下是關(guān)閉的,無論用什么PHP 命令都是格林威治標(biāo)準(zhǔn)時間,但是PHP 5.3 中好像如果沒有設(shè)置也會強(qiáng)行拋出了這個錯誤的,解決此問題,只要本地化一下就行了.
PHP編程一、在頁頭使用date_default_timezone_set()設(shè)置 date_default_timezone_set('PRC'); //東八時區(qū) echo
date('Y-m-d H:i:s');
PHP編程二、在頁頭使用 ini_set('date.timezone','Asia/Shanghai');
PHP編程三、修改 php.ini(如果是 windows 系統(tǒng),那么文件在 C 盤,Windows 目錄下,假如系統(tǒng)是安裝在 C 盤).使用記事本打開 php.ini 查找 date.timezone 去掉前面的分號修改成為:date.timezone = PRC
重啟http服務(wù)(如apache2或iis等)即可!
PHP編程以上三種辦法任選其中一種即可,小編推薦使用第三種辦法,不用每次都要增加額外的代碼.
《PHP應(yīng)用:解決php的“It is not safe to rely on the system’s timezone settings”問題》是否對您有啟發(fā),歡迎查看更多與《PHP應(yīng)用:解決php的“It is not safe to rely on the system’s timezone settings”問題》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/8616.html