Created
June 25, 2018 05:24
-
-
Save dishbreak/fcc41a1896f4816596380c74a83a6aa6 to your computer and use it in GitHub Desktop.
Simple Python Code for Turning Seconds into Hours, Minutes, 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 express_as_duration(delta) | |
timestamp = [] | |
hours = int(delta / (60 * 60)) | |
minutes = int((delta % (60 * 60)) / 60) | |
seconds = delta % 60 | |
if hours > 0: | |
if hours == 1: | |
timestamp.append("1 hour") | |
else: | |
timestamp.append("{} hours".format(hours)) | |
if minutes > 0: | |
if minutes == 1: | |
timestamp.append("1 minute") | |
else: | |
timestamp.append("{} minutes".format(minutes)) | |
timestamp.append("{0:.2f} seconds".format(seconds)) | |
return ', '.join(timestamp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment