How to set Timezone in Laravel 8

July 1, 2021
Laravel

In this article, we are going to cover how you can change the timezone in laravel 8.

Let’s get started.

Step 1: Open Config/app.php file

In the laravel project open the file config/app.php, you will notice the 'timezone' => 'UTC', by default, timezone is set to UTC.

Step 2: Replace UTC with your timezone

Now you will replace UTC with your timezone.

If you don’t know what is code for your timezone, you can check the complete list here of timezones available in PHP.

I will be using Europe/Paris as my timezone. So the file will look like this.

Step 3: Clear the Config Cache

Thats all you need to do 🙂

Bonus Tip:

Now if your developer’s localhost timezone is different from the timezone you needed on the production. Then you need to change this field again and again when you deploy the application.

Good Solution is that you put the that timezone in the env file. Lets do that.

  1. You create the variable in env file
APP_TIMEZONE='Europe/Paris'

2. Then in config/app.php, you will change timezone to following

'timezone' => env('APP_TIMEZONE','UTC'),

3. Clear the Config Cache

php artisan config:clear

So env file will look like this:

And config/app.php will look like this

Conclusion:

Hope you have learned how to set the timezone in laravel and the its bonus tip as well.

Feel free to comment and share your thoughts.

Keep Learning Keep Working 🙂

See you in the next post.

Write a Reply or Comment

Your email address will not be published. Required fields are marked *


Icon