怎么把php的时区配置为本地,PHP本地时区设置
php.ini中:
[Date]
; Defines the default timezone used by the date functions
;date.timezone =
php5中php.ini默認(rèn)是GMT時(shí)間,北京是+8時(shí)區(qū),
不建議在php.ini中修改時(shí)區(qū)設(shè)置可通過php腳本來設(shè)置,若您有自己完全管理權(quán)的服務(wù)器當(dāng)然也可以在php.ini中修改默認(rèn)時(shí)區(qū)設(shè)置
如果沒有權(quán)限改php.ini,
可以用函數(shù)ini_set(),date_default_timezone_set通過以下方法來設(shè)置
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();來查看設(shè)置。
手冊解釋:
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,用來設(shè)置php.ini文件中相關(guān)項(xiàng)的配置,并不是所以的項(xiàng)都可以用這個(gè)函數(shù)來設(shè)置的,具體請參考官方手冊
相關(guān)函數(shù):ini_get(),ini_get_all(),ini_alter(),ini_restore().
總結(jié)
以上是生活随笔為你收集整理的怎么把php的时区配置为本地,PHP本地时区设置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php java 通信_PHP与Java
- 下一篇: python关于字符串的内置函数_Pyt