How do I set TimeZone in Laravel PHP

Published January 17, 2022

In this tutorial, we will learn how to establish the TimeZone in Laravel PHP. In this post, we will manually configure our timezone in the laravel files. Simply follow the steps below:

Step 1: First, create a  new Laravel project in your htdocs using the following command

 

composer create-project --prefer-dist laravel/laravel TimeZone

 

How do I set TimeZone in Laravel PHP

 

Step 2: Now, open your Config/app.php and configure the timezone. By default, you will notice that the timezone is set to UTC

How do I set TimeZone in Laravel PHP 2

 

Step 3: We must now change the UTC to reflect our local timezone. Using Europe/Paris as a timezone, the config file will look like the following

 

How do I set TimeZone in Laravel PHP 3

 

Step 4: In this step, we must clear the cache. Simply execute the php artisan config: clear command to do this

 

Step 5: We are done, let's output our  timezone. Paste the code below in your welcome.blade

 

$current_date_time=Carbon\Carbon:now();

echo $current_date_time;

 

Output

2022-16-01 11:10:27

 

 

Download Source code

 

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

607 Views