在Cakephp 3中更改默认日期时间格式
问题描述:
我正在使用Cake Crud API插件并烘焙所有模型。在Cakephp 3中更改默认日期时间格式
在JSON响应的日期时间格式是这样的:
"created": "2016-08-01T08:49:11+0000"
我希望它看起来像一个正常的DATATIME:
"created": "2016-08-01 08:49:11"
我已经tryied设置应用广泛:
Time::setJsonEncodeFormat('yyyy-MM-dd HH:mm:ss');
没有运气,我也搜索了在Crud插件中的任何时间参考,但我没有finde d出默认的ajax格式来自哪里。
有什么想法?谢谢。
答
如果有人有同样的问题只是添加到您的应用程序控制器:
public function initialize()
{
parent::initialize();
Time::setJsonEncodeFormat('yyyy-MM-dd HH:mm:ss'); // For any mutable DateTime
FrozenTime::setJsonEncodeFormat('yyyy-MM-dd HH:mm:ss'); // For any immutable DateTime
Date::setJsonEncodeFormat('yyyy-MM-dd HH:mm:ss'); // For any mutable Date
FrozenDate::setJsonEncodeFormat('yyyy-MM-dd HH:mm:ss'); // For any immutable Date
}
http://stackoverflow.com/questions/31452882/convert-time-object-of-cakephp-3-in- ymd-format – splash58
请始终提及您的_exact_ CakePHP版本(xxx)!自从CakePHP 3初始发布以来,日期时间的东西已经发生了一些变化。另外,你是否使用了不可变的日期/时间对象([**检查你的引导**](https://github.com/cakephp/)应用程序/ BLOB/3.2.6 /配置/ bootstrap.php中#L217))? – ndm
@ndm我使用的是无法更改的日期/时间,我的CakePHP版本是〜3.2 – beerLantern