php默认时区错误
我在尝试安装 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这不是错误,而是警告,因此它不会阻止您的应用程序运行。
使用 date_default_timezone_set() 在 C:\Server\apache\htdocs\kohana\system\core\Kohana.php 第 136 行显式设置正确的时区
您必须在 有效时区
编辑
正如警告消息本身所述,您实际上有一个比编辑第三方软件文件更干净的选择。即按应有的方式配置 PHP。
php.ini
并调整date.timezone = America/New_York
的值,或
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.
php.ini
and adjust the value ofdate.timezone = America/New_York
or
php_value
directive in your web server config to set it in your vhost configuration or.htaccess
:php_value date.timezone America/New_York
OP 对他自己的问题的评论暗示默认时区不能在 php.ini 中设置,这是不正确的 - 事实上,在许多情况下设置它是首选。由于这个答案是 Google 中“php 默认时区错误”的第一批点击之一,我将为其他人节省一些失去理智的机会。
导致此错误的一个非常常见的原因并不是在正在使用的 php.ini 文件中拼错了区域城市或国家(例如“New York”、“Los Angeles”),而是在文件中包含了嵌入的空格而不是下划线。标识符,因此“拼错”了完整的常量。
这也将执行您想要的操作,而无需在运行时在每个页面上进行设置(在 Windows、Linux 和 OSX 中的 PHP 5.4 和 5.3 上进行了验证):
在 php.ini 中:
另外,如果您已经检查并重新检查了拼写并且确定它是正确的,请确保您正在编辑正在使用的实际 php.ini 文件:
Web上下文(创建一个测试文件 test.php,然后确认其中的
date.timezone
):命令行 Linux/OSX:
命令行 Windows:
详细说明了检索默认日期时区配置的优先顺序 此处。
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:
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):Command line Linux/OSX:
Command line Windows:
The precedence order for retrieving the default date timezone configuration is spelled out in detail here.
如果您无法更改
php.ini
,请将其添加到您的_ss_environment.php
或mysite/_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
ormysite/_config.php
files:date_default_timezone_set('...');
where
...
is one of the valid PHP timezones.