我在 Fedora VM 上安装了 ZendServer CE (PHP 5.2),并且我将系统时区设置为“美国/芝加哥”。我的 php.ini 文件中有 date.timezone = 'UTC',当我调用 date_default_timezone_get() 或在网页上显示日期 ('T') 时,它会显示 'CDT'。
关于 date_default_timezone_get() 的 php.net 文档说在选择默认时区时它遵循以下顺序:
- 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 更改系统时区,并重新启动服务器,date('T') 将返回我将系统时区更改为的内容,而不管 php.ini 中的内容。我也没有 TZ 环境变量,而且我目前没有在我的代码中的任何地方使用 date_default_timezone_set()。
知道会发生什么吗?我意识到我总是可以通过调用 date_default_timezone_set('UTC') 来覆盖系统时区,但如果可能的话我宁愿依赖 php.ini 文件。
感谢您的帮助,
戴夫
最佳答案
我认为您设置了 TZ,即使您认为自己没有设置。请小心,查看本教程以更好地了解 TZ。
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/
同时尝试查看用户的 .bashrc 中有什么
关于Fedora + Zend Server CE 上的 PHP 默认时区问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2602956/