Skip to content

Instantly share code, notes, and snippets.

@minte9
Last active May 23, 2021 09:53
Show Gist options
  • Save minte9/6e4330d6197c348f8af6e1fe70571a68 to your computer and use it in GitHub Desktop.
Save minte9/6e4330d6197c348f8af6e1fe70571a68 to your computer and use it in GitHub Desktop.
# Write a function convert() that returns
# days, hours, minutes, seconds since UTC
# The time module provides a function, also named time,
# that returns the current GMT in “the epoch”
import time
today = time.time()
# SOLUTION
def convert(t):
# SOLUTION
days = int(t) // (3600 * 24)
r = int(t) % (3600 * 24) # remainder
hours = r // 3600; r = r % 3600
minutes = r // 60; r = r % 60
seconds = r
return (
str(days) + " days " + \
str(hours) + " hours " + \
str(minutes) + " minutes " + \
str(seconds) + " seconds "
)
print(convert(today))
# 18769 days 20 hours 16 minutes 9 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment