Created
July 11, 2011 15:43
-
-
Save trivektor/1076125 to your computer and use it in GitHub Desktop.
Convert seconds to hour:minute:seconds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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