98

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

I added a variable in my .env file:

APP_TIMEZONE=Europe/Paris

But this doesn't work. What is the right way to update the timezone?

Null
  • 1,950
  • 9
  • 30
  • 33
StormTrooper
  • 1,731
  • 4
  • 23
  • 37
  • 1
    This should be enough in Lumen 5.2 at least. You may have to set your config/app.php file to use the env('APP_TIMEZONE') var in Laravel though. – Matt Humphrey Aug 24 '16 at 16:57
  • 2
    It works on Lumen 5.1 too. After many days I finally realized that it's not enough to change the server's and DB's timezones - Lumen won't care until you set the timezone on the .env file – Bizarro Oct 11 '16 at 16:34
  • How do you know it's not working ? Is it database records that are off, or php generated time ? Do you have a minimal example to show how you see the wrong time ? – Sherbrow Jan 04 '19 at 10:47
  • it did not for me. why? the time show in the database, late 8 hours... – Daisy Apr 26 '21 at 10:31
  • make sure to `composer update ` and clear the config:cache – mercury Apr 16 '22 at 18:36

17 Answers17

221

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'

The list of timezones for PHP.

francisco
  • 1,387
  • 2
  • 12
  • 23
Md Rashedul Hoque Bhuiyan
  • 10,151
  • 5
  • 30
  • 42
56

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

Prashant Barve
  • 4,105
  • 2
  • 33
  • 42
25

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.

agm1984
  • 15,500
  • 6
  • 89
  • 113
12

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!

Sachin Vairagi
  • 4,894
  • 4
  • 35
  • 61
10

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

(this is my timezone)

7

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

APP_TIMEZONE = 'Asia/Calcutta'
DB_TIMEZONE = '+05:30'
shasi kanth
  • 6,987
  • 24
  • 106
  • 158
7

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

Ankit Jindal
  • 3,672
  • 3
  • 25
  • 37
6

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',
TechPotter
  • 579
  • 8
  • 14
5

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.

Organic Advocate
  • 919
  • 1
  • 15
  • 16
  • 1
    Thanks for this. I tried many other solutions (including the ones you've listed in your summary) and nothing worked. Setting the timezone within the Controller as a Carbon variable seems to have worked for now. – Sheldon Scott May 18 '17 at 03:03
5

You just have to edit de app.php file in config directory Just find next lines

/*
|--------------------------------------------------------------------------
| 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.
|
*/

'timezone' => 'UTC',

And.. chage it for:

'timezone' => 'Europe/Paris',
5

By default time zone of laravel project is **UTC*

  • you can find time zone setting in App.php of config folder

'timezone' => 'UTC',

now change according to your time zone for me it's Asia/Calcutta

so for me setting will be 'timezone' => 'Asia/Calcutta',

  • After changing your time zone setting run command php artisan config:cache

*for time zone list visit this url https://www.w3schools.com/php/php_ref_timezones.asp

Aslam Ansari
  • 75
  • 1
  • 4
1

you can find time zone setting in config/App.php put something like this:

'timezone' => 'Africa/Bujumbura',
0

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).

Eloy Ruiz
  • 739
  • 1
  • 8
  • 14
0

Open the config/App.php file and update the timezone value with 'Europe/Paris'

 /*
|--------------------------------------------------------------------------
| 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.
|
*/

'timezone' => 'Europe/Paris',

Then clear the config cache by running the below artisan command

 php artisan config:clear
Md. Ziyed Uddin
  • 180
  • 1
  • 1
  • 10
0

Laravel 9 Change Timezone changing/setting

Go go, config\app.php -- file in your laravel directory

Where you will get an option -- 'timezone' => 'UTC'

Change this parameter with youy relevent one, Ex: 'timezone' => 'Asia/Kolkata',

PQ RS
  • 41
  • 3
-3

Just changing APP_TIMEZONE=Asia/Colombo in .env and run php artisan lumen-config:cache worked for me in lumen 5.7

SamDevG
  • 1
  • 4
-6

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