在Rails 3或Ruby中将持续时间转换为小时:分钟:秒(或类似)

编程入门 行业动态 更新时间:2024-10-24 08:31:38
本文介绍了在Rails 3或Ruby中将持续时间转换为小时:分钟:秒(或类似)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我感觉有一种简单/内置的方法可以执行此操作,但我找不到它。

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中将持续时间转换为小时:分钟:秒(或类似)

本文发布于:2023-10-16 12:13:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497519.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   中将   持续时间   类似   小时

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!