Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Timezone in Lumen or Laravel 5

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?

like image 725
StormTrooper Avatar asked Oct 01 '15 09:10

StormTrooper


5 Answers

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.

like image 99
Md Rashedul Hoque Bhuiyan Avatar answered Oct 18 '22 19:10

Md Rashedul Hoque Bhuiyan


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

like image 55
Prashant Barve Avatar answered Oct 18 '22 21:10

Prashant Barve


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.

like image 25
agm1984 Avatar answered Oct 18 '22 20:10

agm1984


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!

like image 12
Sachin Vairagi Avatar answered Oct 18 '22 20:10

Sachin Vairagi


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

(this is my timezone)

like image 10
Riowaldy Indrawan Avatar answered Oct 18 '22 19:10

Riowaldy Indrawan