LoginSignup
5
6

More than 5 years have passed since last update.

タイムゾーンの変更と、日付のフォーマット[Rails]

Posted at

タイムゾーンの変更と、日付のフォーマット[Rails]

application.rb
class Application < Rails::Application
  # 追加
  config.i18n.default_locale = :ja
  config.time_zone = 'Tokyo'

  #  ActiveRecord 使用時に DB に書かれる時刻も合わせたい場合は以下も追加
  config.active_record.default_timezone = :local
end

# 追加
Time::DATE_FORMATS[:default] = '%Y/%m/%d %H:%M'

フォーマット利用例

hoge_helper.rb
def format_posted_time(time)
    time.to_s(:default)
end
5
6
0

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
5
6