Search code examples
ruby-on-railsrubyhelper

Convert Time to just Number in Ruby


I have a field in my form that is saved in a time format

t.time :time_from

When saving a time it is saved like this in the DB

2000-01-01 18:00:00 UTC

However I would like to display the output as 18:00 in my view. How would I go about converting this using a helper for example?

Do I need to save it in a better format when going in to the DB or will a helper suffice?


Solution

  • Do this:

    time.strftime("%H:%M")