Change Timezone in Lumen or Laravel 5

前端 未结 15 1343
逝去的感伤
逝去的感伤 2020-11-29 02:56

I am using Lumen framework. How can I change Timezone to Europe/Paris CEST?

I added a varaible in my .env file:

APP_TIMEZONE=Europe/Pari         


        
相关标签:
15条回答
  • 2020-11-29 03:47

    After changing app.php, make sure you run:

     php artisan config:clear
    

    This is needed to clear the cache of config settings. If you notice that your timestamps are still wrong after changing the timezone in your app.php file, then running the above command should refresh everything, and your new timezone should be effective.

    0 讨论(0)
  • 2020-11-29 03:47

    Please try this - Create a directory 'config' in your lumen setup, and then create app.php file inside this 'config' dir. it will look like this -

    <?php return ['app.timezone' => 'America/Los_Angeles'];
    

    Then you can access its value anywhere like this -

    $value = config('app.timezone');
    

    If it doesn't work, you can add this lines in routes.php

    date_default_timezone_set('America/Los_Angeles');
    

    This worked for me!

    0 讨论(0)
  • 2020-11-29 03:48

    Use php time zones from php manual Php time zones

    For example mine i changed from the UTC value in config/app.php with

    'timezone' => 'Africa/Nairobi',
    
    0 讨论(0)
  • 2020-11-29 03:48

    please go to .env file and change the value of AWS_DEFAULT_REGION to special area u want to...

    AWS_DEFAULT_REGION = Asia/Dhaka
    
    0 讨论(0)
  • 2020-11-29 03:49

    There is an easy way to set the default timezone in laravel or lumen.

    This is helpful while working in multiple environments where you can use different timezone based on each environment.

    1. Open .env file present inside the your project directory
    2. Add APP_TIMEZONE=Asia/Kolkata in .env (Your can choose any timezone from the supported timezones)
    3. Open app.php present inside bootstrap folder of your project directory
    4. Add date_default_timezone_set(env('APP_TIMEZONE', 'UTC')); in app.php.

    With this change your project will take your .env set timezone and if there is nothing set then take UTC by default.

    After modifying the time zone setting run command php artisan config:clear so that your changes reflect in your application

    0 讨论(0)
  • 2020-11-29 03:51

    There are two ways to update your code. 1. Please open the file app.php file present in config directory at lool of your project. Go down the page and check Application Timezone where you will find

    'timezone' => 'UTC',
    

    Here you can add your timezone like

    'timezone' => 'Europe/Paris',
    

    If you want to manage your timezone from .env file, then you can add below code in your config.php file.

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

    and add the below line in your .env file.

    APP_TIMEZONE='Europe/Paris'
    

    Please check the link below for more information: https://laravel.com/docs/5.6/configuration#accessing-configuration-values

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