Laravel changing timezone not reflecting the correct time

前端 未结 4 1056
一生所求
一生所求 2020-12-06 07:24

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

相关标签:
4条回答
  • 2020-12-06 07:59

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

    0 讨论(0)
  • 2020-12-06 08:05

    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',
    
    0 讨论(0)
  • 2020-12-06 08:10

    Add this in config/app.php file:

    'timezone' => 'Asia/Singapore'  
    

    After, run this command:

     php artisan config:cache
    
    0 讨论(0)
  • 2020-12-06 08:17

    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.

    0 讨论(0)
提交回复
热议问题