Skip to content


PHP5时区问题

使用php5后发现
echo date(“Y-n-j H:i:s”);
和本地相差了8小时

自PHP 5 >= 5.1.0RC1起
新增了两个函数
date_default_timezone_get()
date_default_timezone_set()
如果未设时区,则默认为UTC

解决方法1
$timezone_identifier = “Asia/Hong_Kong”;//北京时间是”PRC”
date_default_timezone_set($timezone_identifier);

解决方法2
设置php.ini
[Date]
; Defines the default timezone used by the date functions
date.timezone = “Asia/Hong_Kong”

重新启动apache

Posted in PHP, 技术.


No Responses (yet)

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.