【问题标题】:PHP Default Timezone issue on Fedora + Zend Server CEFedora + Zend Server CE 上的 PHP 默认时区问题
【发布时间】:2010-04-08 19:50:47
【问题描述】:

我在 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 文件。

感谢您的帮助,

戴夫

【问题讨论】:

    标签: php linux timezone utc zend-server-ce


    【解决方案1】:

    我认为你设置了 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 中的内容

    【讨论】:

    • 我刚刚弄清楚发生了什么。事实证明,'UTC' 不是 Fedora 上 php.ini 中 date.timezone 的有效选择。我将其更改为“Etc/UTC”并重新启动了 apache,它就可以工作了。谁知道时区会如此复杂?谢谢你的帮助,伊沃。
    猜你喜欢
    • 1970-01-01
    • 2012-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多