Tuesday, September 25, 2007

Helper: ms_to_hh_mm_ss(number)

Convert a number (milliseconds) the format hh:mm:ss


def ms_to_hh_mm_ss(number)
seconds = "%02d" % (number % 6)
minutes = "%02d" % ( (number / 60000 ) % 60)
hours = "%02d" % ( (number / 3600000) % 24)

return (hours + minutes + seconds).scan(/../).join(':')
end


Place this in the applications_helper.rb to make it available everywhere in the application.

No comments: