duanqiao1961 2015-05-21 11:11
浏览 88
已采纳

PHP 5.6 DateTime严格警告时区UTC

I'm currently getting following STRICT warning when creating a UTC datetime from php.

Strict Warning: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'UTC' for 'UTC/0.0/no DST' instead

This is the line of code I'm using.

DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), new DateTimeZone('UTC'));

The strange thing is I'm already using UTC as timezone, but it still outputs this warning. How can I get rid of this?

I'm running php 5.6 on Debian Wheezy.

All my php.ini files contain the following date.timezone setting.

date.timezone = "Europe\Amsterdam"

  • 写回答

1条回答 默认 最新

  • dongpu1331 2015-05-21 13:21
    关注

    Seems I had missed one php.ini file + including the fix (forward slash) as suggested by @Ofir-Baruch it seems to be solved.

    The php.ini I forgot was the hhvm one.

    It failed on console lines since I configured all console php to be executed by hhvm using following command.

    /usr/bin/update-alternatives --install /usr/bin/php php /usr/bin/hhvm 60

    I forgot about that and figured that out when I echo'd following.

    echo phpinfo(); which returns Hip Hop in case of hhvm.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?