PHP 警告:date():依赖系统的时区设置是不安全的。 - OS X

PHP Warning: date(): It is not safe to rely on the system's timezone settings. - OS X

我每次在终端中 运行 命令时都会收到此警告。它从最近更新我所有的自制软件公式和更新作曲家开始。我查看了它引用的文件,但不确定在这里做什么。

完整消息

PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting 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 the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /Users/ste/.composer/vendor/hoa/core/Parameter.php on line 158

在 Parameter.php 的第 158 行,我们有一个函数

/**
 * Initialize constants.
 *
 * @return  void
 */
public static function initializeConstants()
{
    $c                = explode('…', date('d…j…N…w…z…W…m…n…Y…y…g…G…h…H…i…s…u…O…T…U'));
    self::$_constants = [
        'd' => $c[0],
        'j' => $c[1],
        'N' => $c[2],
        'w' => $c[3],
        'z' => $c[4],
        'W' => $c[5],
        'm' => $c[6],
        'n' => $c[7],
        'Y' => $c[8],
        'y' => $c[9],
        'g' => $c[10],
        'G' => $c[11],
        'h' => $c[12],
        'H' => $c[13],
        'i' => $c[14],
        's' => $c[15],
        'u' => $c[16],
        'O' => $c[17],
        'T' => $c[18],
        'U' => $c[19]
    ];

    return;
}'

我根本不在 OS X 上使用 PHP。我的工作有时是通过 VM 或 MAMP 进行的,所以我不确定是否应该使用 Composer 的核心?

使用date_default_timezone_set设置默认时区。或者在php.ini中添加date.timezone = // your timezonehttps://secure.php.net/manual/en/timezones.php 在 php 中有支持的时区列表。

您需要设置时区,可以使用 php.ini 或 php 函数 date_default_timezone_set()

通过php.ini:

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Europe/London 

或使用php:

date_default_timezone_set("Europe/London");