LoginSignup
0
0

More than 3 years have passed since last update.

日付フォーマットの共通化

Posted at

はじめに

日付フォーマットメソッドを共通化して適用する方法について

環境

Rails 5.2.4

やったこと

共通フォーマットの設定はここに記述します。

config/initializers/time_formats.rb
Time::DATE_FORMATS[:datetime_jp] = '%Y年%m月%d日 %H時%M分'

Viewに適用します。

<% @boards.each do |b| %>
  <tr>
    <th><%= f.created_at.to_s(:datetime_jp) %></th>
    <th><%= f.updated_at.to_s(:datetime_jp) %></th>
  </tr>
<% end %>

これが(フォーマット前)
image.png

こうなります(フォーマット後)
image.png

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