php默认时区错误

发布于 2024-08-05 07:26:35 字数 548 浏览 8 评论 0原文

我在尝试安装 Kohana/SilverStripe 时收到以下错误/警告。
这是什么意思以及我该怎么做?

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 'Asia/Calcutta' for '5.5/no DST' instead in C:\Server\apache\htdocs\kohana\system\core\Kohana.php on line 136

提前致谢!

I got the following error/warning while tring to install Kohana/SilverStripe.
What does it mean and What do I do for it?

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 'Asia/Calcutta' for '5.5/no DST' instead in C:\Server\apache\htdocs\kohana\system\core\Kohana.php on line 136

Thanks in Advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雾里花 2024-08-12 07:26:35

这不是错误,而是警告,因此它不会阻止您的应用程序运行。

使用 date_default_timezone_set() 在 C:\Server\apache\htdocs\kohana\system\core\Kohana.php 第 136 行显式设置正确的时区

您必须在 有效时区


编辑

正如警告消息本身所述,您实际上有一个比编辑第三方软件文件更干净的选择。即按应有的方式配置 PHP。

  • 编辑 php.ini 并调整 date.timezone = America/New_York 的值

,或

  • 在 Web 服务器配置中使用 php_value 指令进行设置它位于您的虚拟主机配置.htaccess中:php_value date.timezone America/New_York

This is not an error, but a warning, so it does not block your app from working.

Explicitly set the right timezone using date_default_timezone_set() in C:\Server\apache\htdocs\kohana\system\core\Kohana.php on line 136

You have to choose among valid timezones


Edit

As the warning message itself states you actually have a more clean choice then editing a third party software file. I.e. configuring PHP as it should be.

  • edit your php.ini and adjust the value of date.timezone = America/New_York

or

  • use a php_value directive in your web server config to set it in your vhost configuration or .htaccess: php_value date.timezone America/New_York
动听の歌 2024-08-12 07:26:35

OP 对他自己的问题的评论暗示默认时区不能在 php.ini 中设置,这是不正确的 - 事实上,在许多情况下设置它是首选。由于这个答案是 Google 中“php 默认时区错误”的第一批点击之一,我将为其他人节省一些失去理智的机会。

导致此错误的一个非常常见的原因并不是在正在使用的 php.ini 文件中拼错了区域城市或国家(例如“New York”、“Los Angeles”),而是在文件中包含了嵌入的空格而不是下划线。标识符,因此“拼错”了完整的常量。

这也将执行您想要的操作,而无需在运行时在每个页面上进行设置(在 Windows、Linux 和 OSX 中的 PHP 5.4 和 5.3 上进行了验证):

php.ini 中:

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = America/New_York
;               ^^^^^^^^^^^^^^^^  * Must_Use_Underscores *

另外,如果您已经检查并重新检查了拼写并且确定它是正确的,请确保您正在编辑正在使用的实际 php.ini 文件:

Web上下文(创建一个测试文件 test.php,然后确认其中的 date.timezone):

 <?php phpinfo(); ?> 

命令行 Linux/OSX:

$ php -i | grep "timezone" 

命令行 Windows:

C:\> php -i | find "timezone" 

详细说明了检索默认日期时区配置的优先顺序 此处

The OP's comment to his own question above implies that the default timezone cannot be set in php.ini, which is not true — in fact, in many cases setting it there is preferred. And since this SO answer is one of the first hits in Google for "php default timezone error", I'll save others some lost sanity.

A very common cause of this error is not so much to misspell the zone city or country (e.g. "New York", "Los Angeles") in the php.ini file being used, but instead, to include embedded spaces rather than underscores in the identifier, and thus "misspell" the full constant.

This will also do what you want, without having to set it on every page at runtime (verified on PHP 5.4 and 5.3, in Windows, Linux and OSX):

In php.ini:

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = America/New_York
;               ^^^^^^^^^^^^^^^^  * Must_Use_Underscores *

Also, if you've checked and re-checked the spelling and are certain it's right, make sure you're editing the actual php.ini file that's being used:

Web context (create a test file test.php, and then confirm the date.timezone there):

 <?php phpinfo(); ?> 

Command line Linux/OSX:

$ php -i | grep "timezone" 

Command line Windows:

C:\> php -i | find "timezone" 

The precedence order for retrieving the default date timezone configuration is spelled out in detail here.

水溶 2024-08-12 07:26:35

如果您无法更改 php.ini,请将其添加到您的 _ss_environment.phpmysite/_config.php 文件中:

date_default_timezone_set('...');

其中 ... 是有效的 PHP 时区之一。

If you don't have the ability to change php.ini, add this to your _ss_environment.php or mysite/_config.php files:

date_default_timezone_set('...');

where ... is one of the valid PHP timezones.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文