繁体   English   中英

在laravel中更改时区

[英]Change timezone in laravel

我想将UTC的默认时区更改为亚洲/德黑兰,我可以更改它吗? 我尝试在app.php中更改此代码,但它不起作用。

'timezone' => 'UTC',

'timezone' => 'Asia/Tehran',

更新app.php后运行命令并检查

php artisan config:cache
php artisan cache:clear

您可以在laravel中创建以下类型的路径以清除缓存

Route::get('/clear-cache', function() {

    $configCache = Artisan::call('config:cache');
    $clearCache = Artisan::call('cache:clear');
    // return what you want
});

转到文件config/app.php并查找此条目:

/*
|--------------------------------------------------------------------------
| 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

如您所见,UTC是Laravel的默认值。 所以你可以在这里轻松改变它,比如:

'timezone' => 'Asia/Tehran', - 查看完整列表PHP支持的时区

更改app.php你应该运行这个命令php artisan config:cache

我想知道为什么Laravel团队没有将其放入.env 这似乎是参数的最佳位置。

将此添加到.env

TIME_ZONE = 'put_your/timezone_here'

并在/config/app.php中更改:

'timezone' => 'UTC',

至:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM