Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
38
Help us understand the problem. What is going on with this article?
@quoth

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 
38
Help us understand the problem. What is going on with this article?
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
quoth

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
38
Help us understand the problem. What is going on with this article?