Change Timezone in Lumen or Laravel 5

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

提交回复
热议问题