Skip to content

Instantly share code, notes, and snippets.

@excid3
Created September 6, 2012 16:41
Show Gist options
  • Save excid3/3658333 to your computer and use it in GitHub Desktop.
Save excid3/3658333 to your computer and use it in GitHub Desktop.
Format time differences in seconds
class TimeFormatter
def self.format_time(elapsed)
return if elapsed.nil?
seconds = elapsed % 60
minutes = (elapsed / 60) % 60
hours = (elapsed / 3600)
"%d:%02d:%02d" % [hours, minutes,seconds]
# hours.to_s + ":" + format("%02d",minutes.to_s) + ":" + format("%02d",seconds.to_s)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment