Shpigford
Shpigford

Reputation: 25338

How to show time written out?

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

Answers (3)

Marlin Pierce
Marlin Pierce

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

Dave Newton
Dave Newton

Reputation: 160181

humantime is one option, but Rails already has time_ago_in_words and distance_of_time_in_words.

Upvotes: 1

sailor
sailor

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

Related Questions