怎么把php的时区配置为本地,PHP本地时区设置
php.ini中:
[Date]
; Defines the default timezone used by the date functions
;date.timezone =
php5中php.ini默認是GMT時間,北京是+8時區,
不建議在php.ini中修改時區設置可通過php腳本來設置,若您有自己完全管理權的服務器當然也可以在php.ini中修改默認時區設置
如果沒有權限改php.ini,
可以用函數ini_set(),date_default_timezone_set通過以下方法來設置
date_default_timezone_set('Asia/Shanghai');//'Asia/Shanghai'?? 亞洲/上海
date_default_timezone_set('Asia/Chongqing');//其中Asia/Chongqing'為“亞洲/重慶”
date_default_timezone_set('PRC');//其中PRC為“中華人民共和國”
ini_set('date.timezone','Etc/GMT-8');
ini_set('date.timezone','PRC');
ini_set('date.timezone','Asia/Shanghai');
ini_set('date.timezone','Asia/Chongqing');
通過echo date_default_timezone_get();來查看設置。
手冊解釋:
ini_set
(PHP 4, PHP 5)
ini_set -- Sets the value of a configuration option
Description
string ini_set ( string varname, string newvalue )
Sets the value of the given configuration option. Returns the old value on success, FALSE on failure.
The configuration option will keep this new value during the script's execution, and will be restored
at the script's ending. Not all the available options can be changed using ini_set(). There is a list
of all available options in the appendix.
ini_set 支持php4、php5,用來設置php.ini文件中相關項的配置,并不是所以的項都可以用這個函數來設置的,具體請參考官方手冊
相關函數:ini_get(),ini_get_all(),ini_alter(),ini_restore().
總結
以上是生活随笔為你收集整理的怎么把php的时区配置为本地,PHP本地时区设置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php java 通信_PHP与Java
- 下一篇: 动态规划算法php,php算法学习之动态