LoginSignup
0
0

【Rails 7】アプリを日本時間に

Last updated at Posted at 2024-03-16

【Rails 7】アプリを日本時間に

前提

・Ruby 3.2.2
・Rails 7.0.8

config/application.rbファイルの編集

タイムゾーンを変更する

config\application.rb
class Application < Rails::Application
    config.time_zone = "Asia/Tokyo"
end

表記の変更

年:%Y、月:%m、日:%d
時:%H、分:%M、秒:%s

スラッシュや漢字などを挟むときは、上記表記の間にそのまま入れる

html.erb
<%= user.created_at.strftime('%Y/%m/%d') %>
<%= user.created_at.strftime('%Y/%m/%d %H:%M:%S') %>
<%= user.created_at.strftime('%Y年%m月%d日') %>
<%= user.created_at.strftime('%Y年%m月%d日 %H時%M分%S秒') %>
0
0
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
0
0