Laravel changing timezone not reflecting the corre

2020-02-01 06:37发布

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 ?

4条回答
成全新的幸福
2楼-- · 2020-02-01 06:50

Add this in config/app.php file:

'timezone' => 'Asia/Singapore'  

After, run this command:

 php artisan config:cache
查看更多
Fickle 薄情
3楼-- · 2020-02-01 06:51

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楼-- · 2020-02-01 06:52

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.

查看更多
放我归山
5楼-- · 2020-02-01 07:05

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!!

查看更多
登录 后发表回答