ruby on rails - Show duration (in minutes) to hours -
i want display duration of movie. right movie.duration shown in minutes (integer)
%b duration: #{ @movie.duration } # 134 mins does rails have time helper show in more human-readable way? this:
duration: 2h 23min
distance_of_time_in_words might you
you can use this:
distance_of_time_in_words(0, 143*60) # "about 2 hours" <- result you need *60 because count in seconds, way count in minutes.
edit: can more rails way so:
distance_of_time_in_words(0, 143.minutes) you can calculate this:
"#{@movie.duration/60}h #{@movie.duration % 60}min" the division give hours while modulo give minutes
and if want more said, can use code here:
Comments
Post a Comment