LoginSignup
0
0

More than 1 year has passed since last update.

投稿時刻を日本時刻へ設定する方法

Last updated at Posted at 2021-05-17

投稿時刻の設定をします


configディレクトリに用意されているRailsのapplication.rbファイルに下記を追加します。

module ChatApp
  class Application < Rails::Application
#中略

config.i18n.default_locale = :ja
config.time_zone = 'Tokyo'

続いて、config/localesディレクトリに「ja.yml」というファイルを作成し、以下のような設定を記述します。

ja:
  time:
    formats:
      default: "%Y/%m/%d %H:%M:%S"

時刻の設定は以上です。

時刻を表示させる記述


l(エル)メソッドを使用します。

【例】
<%= l message.created_at %>

lメソッドを使用すると指定した現地時間に対応できます。

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