Advertisement
Guest User

test.py

a guest
Mar 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. import time
  2.  
  3. start_time = int(time.time())
  4.    
  5. def time_from_boot():
  6.     """Return time from boot in
  7.    years, months, days, hours, minutes, seconds"""
  8.     seconds = int(time.time()) - start_time
  9.     minutes, seconds = divmod(seconds, 60)
  10.     hours, minutes = divmod(minutes, 60)
  11.     days, hours = divmod(hours, 24)
  12.     months, days = divmod(days, 30)
  13.     years, months = divmod(months, 12)
  14.    
  15.     time_elapsed = ''
  16.    
  17.     if years >0:
  18.         time_elapsed += str(years) + (years == 1 and ' Year' or ' Years') + ', '
  19.     if months > 0:
  20.         time_elapsed += str(months) + (months == 1 and ' Month' or ' Months') + ', '
  21.     if days > 0:
  22.         time_elapsed += str(days) + (days == 1 and ' Day' or ' Days') + ', '
  23.     if hours > 0:
  24.         time_elapsed += str(hours) + (hours == 1 and ' Hour' or ' Hours') + ', '
  25.     if minutes > 0:
  26.         time_elapsed += str(minutes) + (minutes == 1 and ' Minute' or ' Minutes') + ', '
  27.     if seconds >0:
  28.         time_elapsed += str(seconds) + (seconds == 1 and ' Second' or ' Seconds')
  29.  
  30.     return time_elapsed
  31.  
  32. while True:
  33.     print(time_from_boot())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement