编码日期时间错误


Codeception datetime error

我正在尝试学习Codeception,并在Yii(我也是新手)中使用它。

开箱即用,我在运行测试时遇到了一些问题。我已经浏览了快速入门指南,当我通过终端运行它时,出现此错误:

Codeception PHP Testing Framework v1.6.6
Powered by PHPUnit 3.7.24 by Sebastian Bergmann.
  [Exception]                                                                                                                                         
  DateTime::__construct(): 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 tim  
  ezone identifier. We selected 'America/Chicago' for 'CDT/-5.0/DST' instead                                                                          

现在,我正在使用 MAMP,并在我的 php.ini 文件中设置了时区。我还尝试使用_default_timezone_set('America/Chicago');在索引.php文件中手动设置它,但我仍然收到相同的消息。

当我使用 Yii 时,我尝试为 Codeception 启用 Yii 模块,但这似乎没有任何区别。

更新

我尝试在一个非基于 yii 的项目上安装 codeception,所以一个简单的网站,我得到与上面完全相同的错误。

我遇到了同样的问题,发现在 php 中设置date.timezone设置.ini解决了这个问题。

  1. 打开 php.ini(在 Mac 上是/private/etc/php.ini)
  2. 搜索"时区"。 第一个命中应该是这个设置
  3. 取消注释该行;date.timezone =(删除;)
  4. 将您的时区添加为字符串,例如 "America/New_York",所以整行读date.timezone = "America/New_York"
  5. 保存文件并重新启动 Web 服务器

时区选项列表如下:http://www.php.net/manual/en/timezones.php

希望有帮助。

虽然是的,问题是 php.ini 文件,但最终,我的问题是在 Mac 上直接使用 php。显然,默认安装(在/usr/bin 中)是从终端使用的,而不是从 mac 安装的 PHP。此外,该默认安装没有关联的 PHP.ini 文件。

我从 Yii 的论坛上找到了以下说明,该指令也在播放,结果是相同的错误:

A note on PHP and Mac OSX:
A version of PHP4 comes bundled on Mac OSX and is typically what is executed when you try the php command from the command line.  You need to have the php command execute a version of PHP5.x or higher.  Usually, you have already installed a version of PHP5.x or higher, but need to tell the php command to execute the newer version rather than the older one.  There are certainly many ways to achieve this, but here is one:
at any terminal prompt, type in:
prompt>which php
this should tell you where the OS is looking for the php command
mine tells me /usr/bin/php
if I navigate to /usr/bin and issue an ls *php* I will see three files
php
php-config
phpize
These are all for the bundled version PHP4.x
rename these files to use a 4 in their names, to remember these are the executables for PHP4
mv php php4
mv php-config php-config4
mv phpize phpize4
Then, create sym links for each of these these to point to the PHP5.x or higher version you have installed.  In my case these are located in /usr/local/apache/php/bin.  So I would issue from the /usr/bin directory
ln -s [absolute path to your php5.x] php
and similarly for the other files.

set

use date_default_timezone_set('Europe/Istanbul');

在自动加载中.php