Laravel Change Timezone
By default UTC is set as a default timezone in laravel instalaltion.We can change it very easily.
Step 1 : Adjust the configuration:
Navigate to the
config/app.php
file within your Laravel project.Replace the default value
UTC
with your desired timezone string, ensuring it's a valid PHP timezone identifier (e.g., Asia/Karachi
, America/Los_Angeles
, Europe/London
).// 'timezone' => 'UTC',
'timezone' => 'Asia/Karachi',
Step 2:Clear configuration caches:
After changing the timezone we need to run following commandsphp artisan cache:clear
php artisan config:clear
These commands will clear all config and other cache.
Additional considerations:
- Environment variable: For flexibility across environments, consider setting the timezone using an environment variable:
'timezone' => env('APP_TIMEZONE', 'UTC'),
In env file we can define APP_TIMEZONE constant with the required timezone
That's it. If you have any question please feel fee to ask.
No comments:
Post a Comment