7
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Rails】日本時間を表示したい―タイムゾーンをJSTに変換する方法

Last updated at Posted at 2019-07-28

表示時刻がおかしいなと思ったら

UTC(協定世界時)→JST(日本標準時)に直しましょう。
26895ccc61701727f98f687e13e4f336.png
※画像は日本時間でないことに気づいた瞬間です。えらい深夜ですがJSTに直した後の時刻です。

JSTに変える方法

"config/application.rb"にconfig.time_zone = 'Tokyo'を追加します。

config/application.rb
module Hoge
  class Application < Rails::Application
    #省略
    config.time_zone = 'Tokyo'
  end
end

上の1行を追加できたらrails+sで忘れずにサーバーを立ち上げ直してください。

参考

RailsのTimezone設定をUTCからJSTに変えたい時
↑DBの保存時刻からJSTにする方法をまとめてくださっています。
Railsのタイムゾーンの闇(2) 設定ファイルの書き方
↑詳しく説明してくださっています。

以上を参考に解決することができました。ありがとうございます。

さいごに

こんなに簡単にできるとは、と驚きました。こちらは必要最低限の情報のみなので、参考リンクをあわせてご確認ください。

7
3
3

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
7
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?