Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
92
Help us understand the problem. What is going on with this article?

More than 1 year has passed since last update.

@pinkumohikan

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

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⏎
92
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
92
Help us understand the problem. What is going on with this article?