LoginSignup
60

More than 5 years have passed since last update.

posted at

updated at

Organization

created_atなどに日本語曜日入り日付フォーマットを1行で書く

Qiitaの記事に、これ(http://qiita.com/items/20853d5fce6677d0f346)
で日付を日本語にできるとあるが、これだと現在時刻ばかりなので、
忘れないために便乗して補足しておく。

Time.now.strftime("%m/%d(#{%w(日 月 火 水 木 金 土)[Time.now.wday]})")

例えば、Postモデルのcreated_atを日本語化したいときは、
<% @posts.each do |post| %>
post.created_at.strftime("%Y/%m/%d(#{%w(日 月 火 水 木 金 土)[post.created_at.wday]})")
<% end %>

この1行でおk。

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
What you can do with signing up
60