php 停止警告:date() [function.date]:来自本地主机

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8704522/
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-26 05:19:33  来源:igfitidea点击:

Stop Warning: date() [function.date]: from localhost

phpdatetimezonewarnings

提问by X10nD

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are requiredto 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 ............

警告:date() [function.date]:依赖系统的时区设置是不安全的。您需要使用 date.timezone 设置或 date_default_timezone_set() 函数。如果您使用了这些方法中的任何一种并且仍然收到此警告,则很可能是您拼错了时区标识符。我们选择了…………

There are many web applications that spring up this particular error. I could set

有许多 Web 应用程序会引发此特定错误。我可以设置

date_default_timezone_set('America/Los_Angeles');

But that is not the solution I am looking for.

但这不是我正在寻找的解决方案。

Can I do something from system level. It happens only on LOCALHOSTnot on the actual production server.

我可以从系统级别做一些事情吗?它只发生LOCALHOST在实际的生产服务器上,而不是发生在。

Default set in php.ini is date.timezone = America/Los_Angeles

php.ini 中的默认设置为 date.timezone = America/Los_Angeles

[update]edited php.ini

[更新]编辑了 php.ini

Warning: phpinfo() [function.phpinfo]: 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

警告:phpinfo() [function.phpinfo]:依赖系统的时区设置是不安全的。您需要使用 date.timezone 设置或 date_default_timezone_set() 函数。如果您使用了这些方法中的任何一种并且仍然收到此警告,则很可能是您拼错了时区标识符

回答by mario

The reason it is happending on one server and not the other is the php.inisetting date.timezone=.

它发生在一台服务器上而不是另一台服务器上的原因是php.ini设置date.timezone=

You would still need to pick an actual value though. You assuredly don't have one. Or in the wrong php.ini version (there's one for CLI and one for mod_php).

不过,您仍然需要选择一个实际值。你肯定没有。或者在错误的 php.ini 版本中(一个用于 CLI,一个用于 mod_php)。

回答by David Stockton

As the other posters have mentioned, setting date.timezone in the php.ini file is the way to go. If you are still seeing the error about needing to set it, did you restart your web server (apache, IIS, etc) after setting the php.ini?

正如其他海报所提到的,在 php.ini 文件中设置 date.timezone 是要走的路。如果您仍然看到需要设置它的错误,您是否在设置 php.ini 后重新启动了 Web 服务器(apache、IIS 等)?

Also, the warning from phpinfo means the rest of the output should still be showing. Make sure you're editing the correct php.ini file according to the phpinfo() output.

此外,来自 phpinfo 的警告意味着其余的输出仍应显示。确保根据 phpinfo() 输出编辑正确的 php.ini 文件。

That will likely get you working as you'd like.

这可能会让你按照自己的意愿工作。

回答by Suraj Singh

to remove this warning from your project

从您的项目中删除此警告

There are 2 ways to do so...

有2种方法可以做到这一点......

1) date_default_timezone_set('Asia/Kolkata'); include this file in your index.php file This will work only for your current project

1) date_default_timezone_set('亚洲/加尔各答'); 将此文件包含在您的 index.php 文件中 这仅适用于您当前的项目

2) date_default_timezone_set('Asia/Kolkata'); or inlude this file in your php.ini file This will work for every project

2) date_default_timezone_set('亚洲/加尔各答'); 或者在你的 php.ini 文件中包含这个文件 这将适用于每个项目

thnx :)

谢谢:)

回答by DaveRandom

As the warning says...

正如警告所说......

use the date.timezonesetting

使用date.timezone设置

Just configure this with your timezonein php.ini, and all will be well for all apps on your server.

只需在 php.ini 中使用您的时区进行配置,您服务器上的所有应用程序都将正常运行。

EDITIf you are still having this problem after having configured this, you will probably find that your system uses more than one php.ini file. To find out which ini file is used for your web server, use phpinfo().

编辑如果您在配置后仍然遇到此问题,您可能会发现您的系统使用了多个 php.ini 文件。要找出用于您的 Web 服务器的 ini 文件,请使用phpinfo().

回答by xerosay

It works by setting

它通过设置工作

date.timezone = Asia/Calcutta

For details go to: PHP Documentation - Asia Timezones

有关详细信息,请访问:PHP 文档 - 亚洲时区