Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- start_time = int(time.time())
- def time_from_boot():
- """Return time from boot in
- years, months, days, hours, minutes, seconds"""
- seconds = int(time.time()) - start_time
- minutes, seconds = divmod(seconds, 60)
- hours, minutes = divmod(minutes, 60)
- days, hours = divmod(hours, 24)
- months, days = divmod(days, 30)
- years, months = divmod(months, 12)
- time_elapsed = ''
- if years >0:
- time_elapsed += str(years) + (years == 1 and ' Year' or ' Years') + ', '
- if months > 0:
- time_elapsed += str(months) + (months == 1 and ' Month' or ' Months') + ', '
- if days > 0:
- time_elapsed += str(days) + (days == 1 and ' Day' or ' Days') + ', '
- if hours > 0:
- time_elapsed += str(hours) + (hours == 1 and ' Hour' or ' Hours') + ', '
- if minutes > 0:
- time_elapsed += str(minutes) + (minutes == 1 and ' Minute' or ' Minutes') + ', '
- if seconds >0:
- time_elapsed += str(seconds) + (seconds == 1 and ' Second' or ' Seconds')
- return time_elapsed
- while True:
- print(time_from_boot())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement