问题描述
我希望在schema.org上以ruby在rails中以iso8601格式输出持续时间。我已经知道如何在iso8601中输出时间戳。例如video.created_at.iso8601
I'm looking to output duration in iso8601 format in ruby on rails for schema.org. I already know how to output the timestamp in iso8601. e.g. video.created_at.iso8601
我现在要做的是输出以下格式的内容:
What I'm looking to do now is output something in the format of:
<meta itemprop="duration" content="PT1M33S" />
这是iso8601持续时间格式。您可以在
That's the iso8601 duration format. You can read about the spec at http://en.wikipedia.org/wiki/ISO_8601#Durations
当前我在strftime中进行黑客入侵,但这并不理想...
Currently I'm hacking in a strftime, but that's not ideal...
Time.at(@video.duration).strftime('PT%MM:%SS')
希望能得到更好的解决方案。并且足够聪明,可以在需要时处理小时等。我完全可以依赖ActiveSupport等,因为它会出现在Rails 3.2应用程序中。谢谢!
Would appreciate a classier solution. And one smart enough to handle hours, etc when needed. I have no problem relying on ActiveSupport, etc as it'll be in a Rails 3.2 app. Thanks!
推荐答案
如果您仍在寻找答案,请查看红宝石历时宝石。
If you're still looking for an answer to this, check out the ruby-duration gem.
这篇关于iso8601中的输出Ruby持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!