Skip to content

Instantly share code, notes, and snippets.

@trivektor
Created July 11, 2011 15:43
Show Gist options
  • Save trivektor/1076125 to your computer and use it in GitHub Desktop.
Save trivektor/1076125 to your computer and use it in GitHub Desktop.
Convert seconds to hour:minute:seconds
def format_time_difference(start_time, end_time)
difference = end_time.to_i - start_time.to_i
hours = difference/3600.to_i
minutes = (difference/60 - hours * 60).to_i
seconds = (difference - (minutes * 60 + hours * 3600))
sprintf("%02d:%02d:%02d\n", hours, minutes, seconds)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment