Rails function to get "hours, minutes, seconds" until timestamp?
Have been digging around the docs but cannot find if there is a function to calculate the
- hours
- 开发者_运维百科minutes
- seconds
As separate vars from a ruby date time stamp
Is there a build in function or does one have to calculate it by himself?
From the API docs, check out distance_of_time_in_words
, I think that is what you are looking for.
For instance:
def find_time
distance_of_time_in_words(Time.now, due_at)
end
This will calculate the length of time from now until the timestamp of due_at
. You can pass the option include_seconds = true
to display seconds as well.
精彩评论