Change Timezone in Lumen or Laravel 5

前端 未结 15 1346
逝去的感伤
逝去的感伤 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:35

    I modify it in the .env APP_TIMEZONE.

    For Colombia: APP_TIMEZONE = America / Bogota also for paris like this: APP_TIMEZONE = Europe / Paris

    Source: https://www.php.net/manual/es/timezones.europe.php

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

    In Lumen's .env file, specify the timezones. For India, it would be like:

    APP_TIMEZONE = 'Asia/Calcutta'
    DB_TIMEZONE = '+05:30'
    
    0 讨论(0)
  • 2020-11-29 03:38

    In my case (reading a date from a MySQL db in a Lumen 5.1 project) the only solution that worked is using Carbon to set timezone of variables:

        $carbonDate = new Carbon($dateFromDBInUTC);
        $carbonDate->timezone = 'America/New_York';
        return $carbonDate->toDayDateTimeString(); // or $carbonDate->toDateTimeString() for ISO format
    

    Using DB_TIMEZONE=-05:00 in the .env file almost worked but does not handle DST changes.

    Using the APP_TIMEZONE=America/New_York in the .env file had no effect on a timezone value retrieved in a Lumen 5.1 webapp from a MySQL database, but it works in Lavarel 5.1.

    Also Lumen didn't read at all the [lumen_project]/config/app.php file that I created (it didn't complain when I put a syntax error there).

    Using date_default_timezone_set didn't work either.

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

    Go to config -> app.php and change 'timezone' => 'Asia/Jakarta',

    (this is my timezone)

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

    For me the app.php was here /vendor/laravel/lumen-framework/config/app.php but I also could change it from the .env file where it can be set to any of the values listed here (PHP original documentation here).

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

    You can set your app time zone by configuring app.php file in config folder .

    To change time zone , modify the value of timezone in app.php file.

    This is written in this section

    |--------------------------------------------------------------------------
    | Application Timezone
    |--------------------------------------------------------------------------
    |
    | Here you may specify the default timezone for your application, which
    | will be used by the PHP date and date-time functions. We have gone
    | ahead and set this to a sensible default for you out of the box.
    |
    

    For me i am using Asia/Dhaka as my application time zone.

    Here is the appropriate syntax :

    'timezone' => 'Asia/Dhaka'
    

    list of timezones for PHP 5

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