Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

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⏎
pinkumohikan
プログラマー風林火山で言う「風のエンジニア」になりたい(比較的)若者Webエンジニア。 Blog: https://blog.pinkumohikan.com/
https://blog.pinkumohikan.com/
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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした