I want change the default timezone from UTC to Asia/Tehran where I can change it? I tried by changing this code in app.php but it did not work.
'timezone' => 'UTC',
to
'timezone' => 'Asia/Tehran',
After update app.php run below command and check
php artisan config:cache
php artisan cache:clear
You can create below type of route for clear cache in laravel
Route::get('/clear-cache', function() {
$configCache = Artisan::call('config:cache');
$clearCache = Artisan::call('cache:clear');
// return what you want
});
go to the file config/app.php
and look for this entry:
/*
|--------------------------------------------------------------------------
| 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.
|
*/
'timezone' => 'Asia/Tehran', //There will be default 'UTC' here
As you can see, UTC is a default value for Laravel. So you can easily change it here to, like:
'timezone' => 'Asia/Tehran',
- See full list PHP Supported Timezones
After changes app.php
you should run this command php artisan config:cache
I wonder why Laravel team didn't put this inside .env . It seems like best place for parameter like that.
Add this to .env :
TIME_ZONE = 'put_your/timezone_here'
and in /config/app.php change:
'timezone' => 'UTC',
to:
'timezone' => env('TIME_ZONE', 'UTC'),
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.