PHP & 技术 21 May 2007 04:26 pm

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

Trackback This Post | Subscribe to the comments through RSS Feed

Leave a Reply