LoginSignup
42
39

More than 5 years have passed since last update.

Railsでの、日本語対応の短縮曜日の表示

Posted at

短縮された曜日を表示したい場合、rails-i18nを利用するのが一番楽。

# Rails3系の場合
gem 'rails-i18n', '~> 3.0.0'

このgemをインストールすると、rails-18n内のyml経由で、date.abbr_day_namesの値を取得できる。

> I18n.t 'date.abbr_day_names'
=> ["日", "月", "火", "水", "木", "金", "土"]

この配列を%wの値に応じて、表示させる。

2013年11月30日 (土) 00:00のような日付の出力だけなら、下記のように設定しておくと、もっと簡単に表示できる。

  ja:
    time:
      formats:
         full_date: "%Y年%m月%d日 (%a) %H:%M"

設定した書式を使用する際は、下記のようにフォーマットを指定するだけ。

  I18n.l Time.zone.now, format: :full_date 
42
39
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
42
39