我感觉有一种简单/内置的方法可以执行此操作,但我找不到它。
I have a feeling there is a simple/built-in way to do this but I can't find it.
我有一个持续时间(以秒为单位)
I have a duration (in seconds) in an integer and I want to display it in a friendly format.
例如,以整数形式显示。 3600会显示为 01:00:00或 1 hour之类。
e.g. 3600 would be displayed as "01:00:00" or "1 hour" or something.
我可以使用 time_ago_in_words(Time。 zone.now + 3600),但感觉有点像破解,没有理由从当前时间开始添加/减去该格式的值。是否有 duration_in_words()或其他东西?
I can do it with time_ago_in_words(Time.zone.now+3600) but that feels like a bit of a hack, there is no reason to add/subtract from the current time just to format this value. Is there a duration_in_words() or something?
谢谢
推荐答案请参阅: http:// api.rubyonrails/classes/ActionView/Helpers/DateHelper.html
distance_of_time_in_words(3600) => "about 1 hour"更多推荐
在Rails 3或Ruby中将持续时间转换为小时:分钟:秒(或类似)
发布评论