Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

短縮された曜日を表示したい場合、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 
quoth
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした