开发者

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

开发者 https://www.devze.com 2023-01-19 14:41 出处:网络
Give a model.created_at I\'ve been able to use: <%=\"开发者_Go百科#{time_ago_in_words(model.created_at)} ago \"%>

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

精彩评论

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

关注公众号