Skip to content

Instantly share code, notes, and snippets.

@dishbreak
Created June 25, 2018 05:24
Show Gist options
  • Save dishbreak/fcc41a1896f4816596380c74a83a6aa6 to your computer and use it in GitHub Desktop.
Save dishbreak/fcc41a1896f4816596380c74a83a6aa6 to your computer and use it in GitHub Desktop.
Simple Python Code for Turning Seconds into Hours, Minutes, Seconds
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