date_default_timezone_set

(PHP 5 >= 5.1.0RC1)

date_default_timezone_set -- 设定用于一个脚本中所有日期时间函数的默认时区

说明

bool date_default_timezone_set ( string timezone_identifier )

date_default_timezone_set() 设定用于所有日期时间函数的默认时区。

注: 自 PHP 5.1.0 起(此版本日期时间函数被重写了),如果时区不合法则每个对日期时间函数的调用都会产生一条 E_NOTICE 级别的错误信息。

参数

timezone_identifier

时区标识符,例如 UTCEurope/Lisbon

返回值

本函数永远返回 TRUE(即使 timezone_identifier 参数不合法)。


add a note add a note User Contributed Notes
mira at st dot jyu dot fi
29-Mar-2006 08:37
The Etc/GMT+2, Etc/GMT-5 etc. timezones are incorrectly labeled on systems that use GNU glibc. All the timezone labels starting with "Etc/" have plus and minus characters reversed. That is, if you want time for GMT+4 you have to set the timezone to "Etc/GMT-4". This is because (old) POSIX standard has them this way! The official party line seems to be DO NOT USE Etc/* TIMEZONES. It's not a bug, it's a compability feature!
mikx at mikx dot de
09-Dec-2005 02:29
Be aware that Etc/GMT times are implemented the other way around. So Europe/Berlin is NOT equal Etc/GMT+1 (as you might expect) but is equal Etc/GMT-1.

According to http://bugs.php.net/34710 this is expected behavior.