Changing default datetime format in Cakephp 3

bee*_*ern 4 php cakephp cakephp-3.0

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"
Run Code Online (Sandbox Code Playgroud)

I want it to look like a normal datatime:

"created": "2016-08-01 08:49:11"
Run Code Online (Sandbox Code Playgroud)

I have tryied setting application wide:

Time::setJsonEncodeFormat('yyyy-MM-dd HH:mm:ss');
Run Code Online (Sandbox Code Playgroud)

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.

bee*_*ern 5

如果有人遇到同样的问题,只需将其添加到您的应用程序控制器中:

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

}
Run Code Online (Sandbox Code Playgroud)