I am changing the timezone into Asia/Singapore
at config/app.php
, but when I try to do a date("Y-m-d H:i:s");
the result is still in UTC.
Is there anything in Laravel that overrides that timezone that I set at config/app.php
?
I am changing the timezone into Asia/Singapore
at config/app.php
, but when I try to do a date("Y-m-d H:i:s");
the result is still in UTC.
Is there anything in Laravel that overrides that timezone that I set at config/app.php
?
Add this in
config/app.php
file:After, run this command:
At least in the generated application skeleton of Laravel 5.8, maybe other versions too, the timezone setting in
config/app.php
is'timezone' => 'UTC'
, so it will ignore anAPP_TIMEZONE
in the.env
file.So put an e.g.
APP_TIMEZONE='Europe/Berlin'
in.env
and modify the line inconfig/app.php
to this:Or, when it's sure local, staging and production all run in the same timezone - change only the line in
config/app.php
to:The
date()
function php won't load configuration from Laravelconfig/app.php
. To change timezone you should change it viaphp.ini
ondate.timezone
parameter. Don't forget to restart your apache after change it.Or if you wan't more flexibility, there are
Carbon
package. It has many usefull functions to deal with datetime operation.Just do this:
'timezone' => 'Asia/Singapore'
in
config/app.php
file and run this 3 command:php artisan cache:clear
php artisan view:clear
andphp artisan config:cache
Hope this helps you!!