Convert milliseconds to hours and mins in ruby -


i have following rails helper convert milliseconds hours , mins:

def get_duration_hrs_and_mins(duration)   hours = duration / (3600000 * 3600000)   minutes = (duration / 60000) % 60000   "#{hours}h #{minutes}m"  rescue   "" end 

however returns in minutes (e.g. 364m) , doesn't show hours... , keep minutes under 60.

you have miscalculated number of milliseconds in 1 hour , 1 minute. try following:

def get_duration_hrs_and_mins(duration)   hours = duration / (1000 * 60 * 60)   minutes = duration / (1000 * 60) % 60   "#{hours}h #{minutes}m"  rescue   "" end 

Comments

Popular posts from this blog

sql - can we replace full join with union of left and right join? why not? -

javascript - Parallax scrolling and fixed footer code causing width issues -

iOS: Performance of reloading UIImage(name:...) -