每当我在PHP中使用日期函数时,我都在使用php5.5并收到此错误:
Warning: 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. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /var/www/info.php on line 1
Run Code Online (Sandbox Code Playgroud)
加载的配置文件在这里:
/etc/php5/apache2/php.ini
Run Code Online (Sandbox Code Playgroud)
所以我将date.timezone设置更改为:
[Date]
; Defines the default timezone used by the …Run Code Online (Sandbox Code Playgroud) 保存在数据库中的日期时间值为" 2014-06-30 02:52:51.210201".
这也是Yii显示的值.
将它显示为" 30-06-2014 02:52:51"无处不在的最佳方法是什么?
在Yii的wiki中找到了这个,但不知道如何使用它:
您可以配置yii\i18n\formatter来控制您的区域设置显示的全局日期格式.您可以在配置文件中设置可以访问的类似内容
Run Code Online (Sandbox Code Playgroud)'formatter' => [ 'class' => 'yii\i18n\Formatter', 'dateFormat' => 'd-M-Y', 'datetimeFormat' => 'd-M-Y H:i:s', 'timeFormat' => 'H:i:s', ]`然后,您可以使用格式化程序指定的格式在任何地方显示日期时间:
echo \Yii::t('app', 'Today is {0, date}', $yourTimeStampAttr);
UPDATE
我为模型创建了一个自定义属性来检索时间
public function getFormattedCreateTime()
{
return DateTime::createFromFormat('Y-m-d H:i:s.u', $this->create_time)->format('d-m-Y H:i:s');
}
Run Code Online (Sandbox Code Playgroud)
另一个问题是,如何在Yii 2的GridView中使用此属性进行搜索?谢谢
解决了
可以通过继承搜索功能为搜索添加自定义属性
我有一个类调用另一个类的函数,如下所示:
self.pool.get('some_value')
Run Code Online (Sandbox Code Playgroud)
如何在 get 函数中获取调用者类?
之前谢谢,
标题可能看起来很奇怪,但我真的不知道如何描述这种情况,因为我是JavaScript的初学者.
这是代码:
a={};
var b=a;
b['a']='x';
console.log(a);
Run Code Online (Sandbox Code Playgroud)
结果将是:
Object { a="x"}
Run Code Online (Sandbox Code Playgroud)
它不应该是一个空白对象,因为我只将'x'设置为变量b?