エンジニアとしての市場価値を測りませんか?PR

企業からあなたに合ったオリジナルのスカウトを受け取って、市場価値を測りましょう

0
0

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.

日本時刻設定と表示方法まとめ

Posted at

#はじめに
自分用の備忘録
忘れがちなのでまとめてみる

#手順

日本時刻設定

アプリケーションファイル編集

config/application.rb
# 中略

module App
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 6.0 

    # 日本語の言語設定
    config.i18n.default_locale = :ja
    # 日本時刻の設定
    config.time_zone = 'Tokyo'

    # 中略

時刻のフォーマットを設定

config/locales/ja.yml => 作成
config/locales/ja.yml
ja:
  time:
    formats:
      default: "%Y/%m/%d %H:%M:%S"
      # あくまでデフォルトなのでよく使いそうなパターンで設定

時刻の表示

l(エル)メソッド

sample.rb
l sample.created_at => デフォルトの設定で表示

表示方法を指定

sample.rb
sample.created_at.strftime('20%y年%m月') => "20xx年yy月"

#おわりに
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

Comments

No comments

Let's comment your feelings that are more than good

0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Login to continue?

Login or Sign up with social account

Login or Sign up with your email address