LoginSignup
109

More than 5 years have passed since last update.

LaravelのtimezoneをデフォルトのUTCからJST(日本標準時)へ変更する

Last updated at Posted at 2017-08-15

PHPフレームワークのLaravelでは、default timezoneがUTCになっています。
設定を変えずにそのまま運用してしまうとアプリケーションが扱う日時がおかしくなってしまいます(ログに吐かれる日時や、DB Recordのcreated_at/updated_atなどが9時間前ずれてしまう、など)。

timezoneの変更方法

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' => 'UTC',

こうじゃ
( ^ω^)
≡⊃⊂≡

/*
|--------------------------------------------------------------------------
| 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/Tokyo',

動作確認

before

$ php artisan tinker
Psy Shell v0.8.11 (PHP 7.1.5 — cli) by Justin Hileman
>>> echo Carbon\Carbon::now();
2017-08-15 12:44:55⏎

after

$ php artisan tinker
Psy Shell v0.8.11 (PHP 7.1.5 — cli) by Justin Hileman
>>> echo Carbon\Carbon::now();
2017-08-15 21:44:09⏎

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
109