php5.1x的時區問題!

gudesheng發表於2008-01-03

從php5.10開始,php中加入了時區的設定,在php中顯示的時間都是格林威治標準時間,這就造成了我們中國的使用者會差八個小時的問題!
相關設定是修改php.ini中的 date.timezone 引數:
[Date]
; Defines the default timezone used by the date functions
;date.timezone =

預設是關閉的,只需把註釋去掉,改為即可
[Date]
; Defines the default timezone used by the date functions
date.timezone = PRC

其中PRC是“中華人民共和國”!
其他選項可以參考php手冊
不過這上面的亞洲地區漏掉了我們的首都北京,不知道老外是不是故意的!

如果沒有修改php.ini的許可權,只需要在呼叫時間日期函式的時候,呼叫 date_default_timezone_set(’PRC’) 即可!
也可以呼叫date_default_timezone_get()來檢視當前的時區設定!

<?php
date_default_timezone_set('PRC');
echo date('Y-m-d H:i:s');
?>



Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=767558


相關文章