深入解析PHP 5.3.x 的strtotime() 時區設定 警告資訊修複_PHP教程

來源:互聯網
上載者:User
PHP Warning:
strtotime(): 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' instead in /var/www/cacti/index.php
查了一些資料,說是PHP版本太高,在新版本中必須指定timezone之類的。

具體操作方式如下:
1、在php設定檔中添加timezone的配置
(參照debian的配置規則,添加小的配置規則檔案即可,好維護,自訂性好)
~# vim /etc/php/cli-php5.3/ext-active/date_timezone.ini
date.timezone = "Asia/Shanghai"
~ # env-update
~ # source /etc/profile
自訂的檔案放在cli-php5.3/ext-active目錄中,是因為php預設是採用cli方式,另外ext-active目錄是表示啟用特性的專用目錄,這個可以從/etc/env.d/20php5.3檔案中看出來
MANPATH="/usr/lib/php5.3/man/"
CONFIG_PROTECT_MASK="/etc/php/cli-php5.3/ext-active/ /etc/php/cgi-php5.3/ext-active/ /etc/php/apache2-php5.3/ext-active/"

2、在出現錯誤提示的php檔案中添加date_default_timezone_set('Asia/Shanghai');位置是在中國上海

註:
在某些參考資料中是說這兩個方法任選其一就可,但經我測試,必須兩個方法同時使用,才不會再出現錯誤提示。

經實測其實第二個方法並不需要在每個出現錯誤提示的PHP檔案中添加,只需在其中一個PHP檔案中添加即可。另外添加的時區不需要與提示中的時區一樣,比如系統給我的提示是Chongqing,但我設定成Shanghai也是一樣的,當然這個時間也是與我系統的時區設定是一樣的。

http://www.bkjia.com/PHPjc/328081.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/328081.htmlTechArticlePHP Warning: strtotime(): 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....

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.