With CakePHP 5, time localization is built in. Edit the /config/app.php
file and you'll see the following under the App
configuration:
'defaultTimezone' => env('APP_DEFAULT_TIMEZONE', 'UTC'),
The Cake Book recommends keeping it set to UTC, getting every user's personal time zone, then format the output to match their zone (https://book.cakephp.org/5/en/views/helpers/time.html#using-the-helper). I've never written any "global" applications, and I typically have no need for the users to see any timestamps, so I don't worry about time zones. For my needs I just set the time zone to mine and don't bother wasting time and space in the database to store individual time zones for each user. Do what works best for you and your application.
In /config/app_local.php
I make the below addition to match my time zone. You can find yours here: http://php.net/manual/en/timezones.php
'App' => [
'defaultTimezone' => env('APP_DEFAULT_TIMEZONE', 'America/New_York'),
],
Now in the /config/bootstrap.php
file is set the default locale for the app which is pulled from your PHP environment. Again, personal preferences here, I like mostly ISO date/times, not the US month/day/year. At the bottom of the file I add the following for ISO dates:
Cake\I18n\Date::setToStringFormat('Y-MM-dd');
Cake\I18n\DateTime::setToStringFormat('Y-MM-dd HH:mm');
You can manually set the display of any date/time individually in your views using $model->date_field->format('Y-m-d')
for example. But why would you want to constantly keep worrying about every individual date field when you can set it once, and then just focus on the exceptions?