Reputation: 25338
With Rails, how do I write the time out, like this:
2 days 12 hours 5 minutes and 14 seconds
I feel like there's a Date helper that does it, but digging around the docs hasn't surfaced anything.
Upvotes: 0
Views: 152
Reputation: 10079
You can use DateTime.strftime. It works the same as the C strftime, so you can find documentation on the web.
DateTime.strftime("%j days %H hours %M minutes and %S seconds")
Upvotes: 1
Reputation: 160181
humantime is one option, but Rails already has time_ago_in_words and distance_of_time_in_words.
Upvotes: 1
Reputation: 8034
It looks like http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#method-i-distance_of_time_in_words
If not you can be inspired by the source code of this helper
Upvotes: 0