php date_default_timezone_get():依赖系统的时区设置是不安全的

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12543236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:46:25  来源:igfitidea点击:

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

symfonytimezonephp

提问by Radolino

Can anyone tell me why am I getting this error when running app/console in a brand new formatted macbook with the latest MAMP installed ?

谁能告诉我为什么在安装了最新 MAMP 的全新格式化 macbook 中运行应用程序/控制台时会出现此错误?

Warning: date_default_timezone_get(): 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 'Europe/Helsinki' for 'EEST/3.0/DST' instead in /../Logger.php line 112

警告:date_default_timezone_get():依赖系统的时区设置是不安全的。您*需要*使用 date.timezone 设置或 date_default_timezone_set() 函数。如果您使用了这些方法中的任何一种并且仍然收到此警告,则很可能是您拼错了时区标识符。我们在 /../Logger.php 第 112 行中为“EEST/3.0/DST”选择了“Europe/Helsinki”

I have checked the path of php.ini and marked out the date.timezone = "Europe/Athens"

我已经检查了 php.ini 的路径并标出了 date.timezone = "Europe/Athens"

Also restarted MAMP/apache several times.

还多次重新启动 MAMP/apache。

采纳答案by moonwave99

Default php.iniin OS X is located at:

php.iniOS X 中的默认值位于:

/private/etc/php.ini

Anyway, you'll can either tell CLI php to load MAMP settings, or use an alias of MAMP command itself.

无论如何,您可以告诉 CLI php加载 MAMP 设置,或者使用MAMP 命令本身别名

回答by Filipe Fernandes

At AppKernel.php write:

在 AppKernel.php 写:

public function init() {
    date_default_timezone_set( 'Europe/Lisbon' );
    parent::init();
}

Since init()is deprecated (and will be remove in Symfony2 3.0) it is recommended to move the code in the constructor as in the following exemple:

由于init()已被弃用(并将在 Symfony2 3.0 中移除),因此建议在构造函数中移动代码,如下例所示:

public function __construct($environment, $debug) {
    parent::__construct($environment, $debug);
    // get rid of Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone
    date_default_timezone_set( 'Europe/Paris' );
}

回答by acubens

You don't edit the good php.ini file

你没有编辑好的 php.ini 文件

You can get a full phpinfo() using :

您可以使用以下方法获取完整的 phpinfo():

php -i 

And, in there, there is the php.ini file used :

而且,在那里,使用了 php.ini 文件:

$ php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini

回答by B. Clincy

I had the same problem, and it's true there is a command line, and MAMP/Native Mac PHP service running on Yosemite, and while I was trying to follow the directions on this page non of them seemed to work for me.

我遇到了同样的问题,确实有一个命令行和 MAMP/Native Mac PHP 服务在 Yosemite 上运行,当我试图按照此页面上的说明进行操作时,它们似乎对我不起作用。

When I ran php command:

当我运行 php 命令时:

$ php -i | grep 'Configuration File'<br>
Configuration File (php.ini) Path => /etc<br>
Loaded Configuration File => <em>(Blank)</em>

I realized that the php.ini that the CLI was using, was actually php.ini.default file. I created a symbolic link to that file as the php.ini and everything worked.

我意识到 CLI 使用的 php.ini 实际上是 php.ini.default 文件。我创建了一个指向该文件的符号链接作为 php.ini 并且一切正常。

My-MacPro:/etc/$ ln -s php.ini.default php.ini

My-MacPro:/etc/$ln -s php.ini.default php.ini

回答by crmpicco

I had the exact same problem with my SF2 installation.

我的 SF2 安装遇到了完全相同的问题。

To fix this just go into your php.inifile at /etc/php.iniand change your file to look like this (adjust your timezone to suit your local timezone):

要解决此问题,只需进入您的php.ini文件/etc/php.ini并将您的文件更改为如下所示(调整您的时区以适合您当地的时区):

;;;;;;;;;;;;;;;;;;; ; Module Settings ; ;;;;;;;;;;;;;;;;;;;

[Date] 
; Defines the default timezone used by the date functions 
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone 
date.timezone = Europe/London

回答by Franck

I did follow your answers, but in my case none of them worked. I decided to go change the date_default_timezone_get()in the logger.phpfile.

我确实遵循了您的答案,但就我而言,它们都不起作用。我决定去改变 date_default_timezone_get()logger.php文件。

I replaced with my timezone setting ("Europe/Berlin"), and all went well !

我替换了我的时区设置(“欧洲/柏林”),一切顺利!

Old school solution but still a solution.

老派的解决方案,但仍然是一个解决方案。

回答by Víctor Hugo Valle Castillo

Your default php.in in Mac OSX is located at /etc/php.iniwhich is exactly the same than the /private/etc/php.inifile.

您在 Mac OSX 中的默认 php.in 位于/etc/php.ini/private/etc/php.ini文件完全相同的位置。

You should know that you have the possibility of using two php version running in parallel. I had this issue 'cause I was using the native mac osx php, however I had to install a php package through homebrew, then I got the other version of php through homebrew. though I had the time zone already configured in my php.inifile at /etc/php.ini, I still had the same problem, so I run:

您应该知道您有可能使用两个并行运行的 php 版本。我遇到了这个问题,因为我使用的是本机 mac osx php,但是我必须通过自制软件安装一个 php 包,然后我通过自制软件获得了其他版本的 php。虽然我已经在我的php.ini文件中配置了时区/etc/php.ini,但我仍然遇到同样的问题,所以我运行:

php -i | grep 'Configuration File'

in order to configure the correct file, so I got:

为了配置正确的文件,所以我得到:

Configuration File (php.ini) Path => /usr/local/etc/php/5.3
Loaded Configuration File => /usr/local/etc/php/5.3/php.ini
PHP Warning:  Unknown: 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 
'America/Buenos_Aires' for 'ART/-3.0/no DST' instead in Unknown on line 0

Then I knew I had to edit the /usr/local/etc/php/5.3/php.inifile.

然后我知道我必须编辑/usr/local/etc/php/5.3/php.ini文件。

After that, It all went right. I had not that issue any more.

之后,一切顺利。我不再有那个问题了。

I hope it helps you to solve that.

我希望它可以帮助你解决这个问题。

回答by Evgeny Boyko

I had a similar problem on OS X 10.9. The problem in my case was the absence of a php.inifile in /etc. I solved the problem by creating that php.inifile with the contents:

我在 OS X 10.9 上遇到了类似的问题。在我的情况的问题是缺少的php.ini文件/etc。我通过创建php.ini包含以下内容的文件解决了这个问题:

date.timezone = Europe/Athens

回答by andresgz

By default Mac uses in the console the PHP located at:

默认情况下,Mac 在控制台中使用位于以下位置的 PHP:

/private/etc/php.ini

/private/etc/php.ini

You should use this one because MAMP always unset the timezone variable and you would always get that error.

你应该使用这个,因为 MAMP 总是取消设置时区变量,你总是会得到那个错误。

回答by Elnur Abdurrakhimov

Usually, there are separate php.inifiles for CLI and Apache. Make sure you've edited the needed one.

通常,php.iniCLI 和 Apache有单独的文件。确保您已经编辑了所需的内容。