我正在使用Cake Crud Api插件并烘焙所有模型。
json响应中的datetime格式如下:
"created": "2016-08-01T08:49:11+0000"
我希望它看起来像正常的数据时间:
"created": "2016-08-01 08:49:11"
我尝试设置整个应用程序:
Time::setJsonEncodeFormat('yyyy-MM-dd HH:mm:ss');
运气不好,我也在Crud插件中搜索了任何Time引用,但是我还没有找到默认的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
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句