我在 php 中遇到时区错误


Im having error regarding the timezone in php

我有这个错误:

date_create(): It is not safe to rely on the system's timezone settings.

所以我修改了我的配置.php从:

$config['time_reference'] = 'local';

自:

$config['time_reference'] = 'gmt';

修改后,我收到此错误:

Message: mktime(): 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.

我在我的代码上尝试了这个:

date_default_timezone_set('America/New_York');

这可能有效,但我想修改配置.php所以我不应该一直在我的代码中包含date_default_timezone_set()

将此代码放在配置文件中。

date_default_timezone_set('Etc/GMT');

date_default_timezone_set('America/New_York');

尝试使用它

date_default_timezone_set('America/New_York');

在您的配置中.php

如果您检查php.ini文件并查找此特定部分怎么办:date.timezone

PHP.ini

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

date.timezone 定义所需的时区。如果您的 php .ini 中不存在此行,只需创建一个并定义您想要的时区。

如果您希望在 CI 上设置自己的全局时区,我通常会将其放在应用程序根目录的index.php顶部。