3

我在 Fedora VM 上安装了 ZendServer CE (PHP 5.2),并且我将系统时区设置为“美国/芝加哥”。我的 php.ini 文件中有 date.timezone = 'UTC',当我调用 date_default_timezone_get() 或在网页上显示 date('T') 时,它会显示“CDT”。

php.net 上 date_default_timezone_get() 的文档说它在选择默认时区时遵循以下顺序:

 - Reading the timezone set using the
   date_default_timezone_set() function
   (if any)
 - Reading the TZ environment variable
   (if non empty)
 - Reading the value of the
   date.timezone ini option (if set)
 - Querying the host operating system
   (if supported and allowed by the OS)

如果我通过“设置”GUI 更改系统时区并重新启动服务器,无论 php.ini 说什么,date('T') 都会返回我将系统时区更改为的任何内容。我也没有 TZ 环境变量,我目前没有在我的代码中的任何地方使用 date_default_timezone_set() 。

知道会发生什么吗?我意识到我总是可以通过调用 date_default_timezone_set('UTC') 来覆盖系统时区,但如果可能的话,我宁愿依赖 php.ini 文件。

谢谢您的帮助,

戴夫

4

1 回答 1

1

I think you have TZ set, even though you think you don't. Please be careful, check this tutorial to understand TZ better.

http://www.cyberciti.biz/tips/date-command-set-tz-environment-variable.html http://www.cyberciti.biz/faq/howto-linux-unix-change-setup-timezone-tz-variable/

Also try to see what is in your user's .bashrc

于 2010-04-08T20:39:07.773 回答