Setting the time zone does not change the displayed time in CakePHP 3.x

I am using CakePHP 3.x and have a clock problem.

I have the correct clock in my database (MySQL). When my application displays this watch, I have a watch in UTC instead of my entries. In other words, I have 10:00 recorded in my database and 08:00 displayed on my website

In 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 had time at UTC. Maybe I missed something?

Thank you in advance

+6
source share
3 answers

I found this solution:

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

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

I don't know if this is correct, but it works

+9
source

For CakePHP 3.0, set the default time zone 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'); 

PHP timezone list.

To synchronize it with the database, also set the database time zone in the application line 216-238 on the app.php page

 '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

+5
source

date_default_timezone_set('Europe/Paris'); used to display the date ("Ym-d") or similar information in the time zone or it will affect the moment the information is saved and will be stored in the time zone of the time zone instead of UTC, changing this parameter will only affect how the information is stored. Check here for more information:

http://php.net/manual/en/function.date-default-timezone-set.php

if you want to change the way information is displayed in different time zones for each user, always save the information in the same time zone always, check below:

http://book.cakephp.org/3.0/en/views/helpers/time.html#using-the-helper

echo $this->Time->format( $post->created, \IntlDateFormatter::FULL, null, $user->time_zone );

+2
source

Source: https://habr.com/ru/post/986488/


All Articles