Laravel changing timezone not reflecting the corre

2020-02-01 06:07发布

问题:

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 ?

回答1:

Just do this:

'timezone' => 'Asia/Singapore'

in config/app.php file and run this 3 command:

php artisan cache:clear

php artisan view:clear and

php artisan config:cache

Hope this helps you!!



回答2:

Add this in config/app.php file:

'timezone' => 'Asia/Singapore'  

After, run this command:

 php artisan config:cache


回答3:

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 an APP_TIMEZONE in the .env file.

So put an e.g. APP_TIMEZONE='Europe/Berlin' in .env and modify the line in config/app.php to this:

'timezone' => env('APP_TIMEZONE', 'UTC')

Or, when it's sure local, staging and production all run in the same timezone - change only the line in config/app.php to:

'timezone' => 'Europe/Berlin',


回答4:

The date() function php won't load configuration from Laravel config/app.php. To change timezone you should change it via php.ini on date.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.