0
I’d like to know how calculate the time between creating a record (created_at) and the current time. My intention is to display this difference in seconds, minutes, hours or days that it occurred. Is there any method/Gem to accomplish this task?
0
I’d like to know how calculate the time between creating a record (created_at) and the current time. My intention is to display this difference in seconds, minutes, hours or days that it occurred. Is there any method/Gem to accomplish this task?
1
I have resolved the question using the following method: time_ago_in_words
In your view use the code:
há <%= time_ago_in_words(notification.created_at) %>
If your date passed as a parameter in the method is 19:00 13/12/2017
and the current time is 19:07 13/12/2017
, the result will be: há 07 minutos
. It also works when the difference is for seconds, hours and days.
Browser other questions tagged ruby-on-rails ruby
You are not signed in. Login or sign up in order to post.