Reputation: 492
I am using Cake Crud Api plugin and baking all models.
The datetime format in the json response is like this:
"created": "2016-08-01T08:49:11+0000"
I want it to look like a normal datatime:
"created": "2016-08-01 08:49:11"
I have tryied setting application wide:
Time::setJsonEncodeFormat('yyyy-MM-dd HH:mm:ss');
with no luck and also I have searched for any Time reference in the Crud plugin, but I haven't finded out where the default ajax format comes from.
Any idea? Thanks.
Upvotes: 5
Views: 2493
Reputation: 492
If someone has the same problem just add this to your app controller:
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
}
Upvotes: 6