开发者

rails 3 - given XXX.created_at - How to output the 3 digit month + Day

Give a model.created_at

I've been able to use:

<%="开发者_Go百科#{time_ago_in_words(model.created_at)} ago "%>

What is the helper to output something like

  • Oct 8
  • Sep 23
  • Aug 31
  • Jul 11

Bonus points, if it outputs like above, but for any records that were created today (not 24hrs ago but today). it shows the time, example:

  • 4:31pm
  • 1:20pm
  • 9:31am
  • Oct 8
  • Sep 23
  • Aug 31
  • Jul 11

Thanks


How about a helper method like:

def formated_date(date)
  if date > Time.now.beginning_of_day
    return date.strftime("%l:%M%p")
  end
  date.strftime("%b %d")  
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜