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
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
For CakePHP 3.0, Set default timezone in bootstrap.php Line 95-99
/**
* Set server timezone to UTC. You can change it to another timezone of your
* choice but using UTC makes time calculations / conversions easier.
*/
date_default_timezone_set('Asia/Karachi');
List of PHP Timezones.
To keep it in sync with Database, also set the Database timezone in app.php Line 216-238
'Datasources' => [
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
/**
* CakePHP will use the default DB port based on the driver selected
* MySQL on MAMP uses port 8889, MAMP users will want to uncomment
* the following line and set the port accordingly
*/
//'port' => 'non_standard_port_number',
'username' => 'root',
'password' => '',
'database' => 'invoicing',
'encoding' => 'utf8',
'timezone' => '+8:00', // It can be UTC or "+10:00" or "-4:00"
'flags' => [],
'cacheMetadata' => true,
'log' => false,
MySQL Reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With