Adding time at which tweet or any text created in rails

1–2 minutes

read

Adding time at which tweet or any text created in rails

Screen Shot 2017-07-13 at 9.42.43 PM
My code

So, for adding time use the above code

if tweet or text was added before 24 hours then it will display as 2 hours ago or 4 hours ago and if more than a day time then it will display date.

 

<% if tweet.created_at > Time.now.beginning_of_day %>
<%=”#{time_ago_in_words(tweet.created_at)} ago”%>
<% else %>
<%= tweet.created_at.strftime(“%b %d, %Y”) %>
<% end %>

enjoy!

 

Leave a comment