Set timezone doesn't change displayed time in CakePHP 3.x

Jun picture Jun · May 4, 2015 · Viewed 14.5k times · Source

I am using CakePHP 3.x and have an issue with hours.

I have correct hours in my database (MySQL). When my application displays these hours, I have hours in UTC instead of my records. In others words, I have 10:00 recorded in my database and 08:00 displayed on my website

According to the Cookbook, I tried to change

date_default_timezone_set('UTC');

to

date_default_timezone_set('Europe/Paris');

in config/bootstrap.php

But I still got times in UTC. Maybe I missed something ?

Thanks in advance

Answer

Jun picture Jun · May 11, 2015

I found this solution :

In config/app.php, leave timezone in Datasources array empty :

'Datasources' => [
    'default' => [
        /* previous code */
        'timezone' => '',
        /* next code */
    ],
]

I don't know if it's correct but it works