开发者

Rails function to get "hours, minutes, seconds" until timestamp?

开发者 https://www.devze.com 2023-04-11 17:53 出处:网络
Have been digging around the docs but cannot find if there is a function to calculate the hours 开发者_运维百科minutes

Have been digging around the docs but cannot find if there is a function to calculate the

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.

0

精彩评论

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

关注公众号