php如何設定時間,php.ini如何設定時間,PHP Warning: date() [function.date]: It is not safe to rely on the system's timezone

來源:互聯網
上載者:User
php如何設定時間,php.ini如何設定時間,PHP Warning: date() [function.date]:
It is not safe to rely on the system's timezone
在用PHP5.3以上的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.time
zone 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"
都是timezone惹的禍。
這個問題,從 PHP 5.1.0 ,當對使用date()等函數時,如果date.timezone設定不正確,在每一次調用時間函數時,都會產生E_NOTICE 或者 E_WARNING 資訊。而又在php5.1.0中,date.timezone這個選項,預設情況下是關閉的,無論用什麼php命令都是格林威治標準時間,但是PHP5.3中好像如果沒有設定也會強行拋出了這個錯誤的,解決此問題,只要設定一下timezone,就行了。

以下是data問題的三種解決方案:
1、在頁頭使用date_default_timezone_set()設定 date_default_timezone_set('PRC'); //東八時區 echo date('Y-m-d H:i:s');
2、在頁頭使用 ini_set('date.timezone','Asia/Shanghai');
3、修改php.ini。開啟php5.ini尋找date.timezone 去掉前面的分號修改成為:date.timezone =PRC
重啟http服務(如apache2或iis等)即可。
XXX可以任意正確的值。對於我們國內來說:可以為以下值:Asia/Chongqing ,Asia/Shanghai ,Asia/Urumqi (依次為重慶,上海,烏魯木齊)港台地區可用:Asia/Macao ,Asia/Hong_Kong ,Asia/Taipei (依次為澳門,香港,台北),還有新加坡:Asia/Singapore,當然PRC也行。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.