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

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -