Framework: Update timezone (config/app.php) in Laravel 5.2 does not work.

Created on 22 Jul 2016  路  6Comments  路  Source: laravel/framework

Hi all,

I'm currently working on an app based on Laravel 5.2 and I'm facing a problem with dates. In my php.ini I've got as date.timezone "Europe/Madrid". In my config/app.php, I've got "timezone" => "Europe/Madrid".

With this configuration, when I try something like this in a route:

die(var_dump(date('Y-m-d H:i:s'))); => Results in an UTC time (2 hours of delay).
or
die(var_dump(config('app.timezone')); => It results in the string "UTC"

I was reading the docs and I know that the UTC time is the default behaviour for Laravel but I have changed it to "Europe/Madrid".

I have also tried to create an environment variable as:

In .env file:
APP_TIMEZONE=Europe/Madrid

In config/app.php
"timezone" => env("APP_TIMEZONE"); or env("APP_TIMEZONE", "Europe/Madrid");

When I tried to get config("app.timezone"), it always returns "UTC".

Am I forgetting somewhere to update the timezone? I solve this problem by adding the following line at the very top of my routes.php but I don't like this kind of solution:

date_default_timezone_set('Europe/Madrid');

Thank you all in advance.

Most helpful comment

Looks like you forgot to run php artisan config:cache.

All 6 comments

Looks like you forgot to run php artisan config:cache.

What a terrible and noob mistake!

Thank you for the fastest answer ever :D

Hey there, just found this issue and thought I'd comment on it rather than opening up a new one.

I'm using Laravel 5.4 and cache clearing does not work. No matter what I set APP_TIMEZONE in my .env to, it never changes the UTC-thing. env('APP_TIMEZONE') is always returning 'UTC', even with the default value omitted. Any ideas?

@nathanlesage did you change the timezone key in config/app.php to
"timezone" => env("APP_TIMEZONE"); or env("APP_TIMEZONE", "UTC"); as @juliolopeztorres suggested?

I'm having the same issue in Lumen 5.3. I changed the timezone in config/app.php and .env but _config:cache_ command is not available, what are my options aside from installing this command package manually as I would not be permitted to do this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jackmu95 picture jackmu95  路  3Comments

klimentLambevski picture klimentLambevski  路  3Comments

lzp819739483 picture lzp819739483  路  3Comments

SachinAgarwal1337 picture SachinAgarwal1337  路  3Comments

Fuzzyma picture Fuzzyma  路  3Comments