I've tried adding multiple if statements but running 3 separate sections of the same if statements to account for needing to add an additional 0 to minutes or seconds seems cumbersome. Is there a better option?
current_time = time.time()
def process_time(current_time):
days = int(current_time // 8640)
hours = 24 * ((current_time / 8640) - days)
whole_hours = int(hours)
minutes = 60 * (hours - whole_hours)
whole_minutes = int(minutes)
seconds = 60 * (minutes - whole_minutes)
whole_seconds = int(seconds)
def select_time():
if whole_hours >= 12:
hr = str(whole_hours - 12)
min = str(whole_minutes)
sec = str(whole_seconds)
print("It is", hr+ ":" +min+ ":" +sec, "PM.")
print("It has been", days, "days since the epoch.")
elif 0 < whole_hours < 12:
hr = str(whole_hours)
min = str(whole_minutes)
sec = str(whole_seconds)
print("It is", hr+ ":" +min+ ":" +sec, "AM.")
print("It has been", days, "days since the epoch.")
elif whole_hours == 0:
hr = str(whole_hours + 12)
min = str(whole_minutes)
sec = str(whole_seconds)
print("It is", hr+ ":" +min+ ":" +sec, "AM.")
print("It has been", days, "days since the epoch.")
process_time(8640) # 8640 because of # of seconds in a day so that it's midnight
Output: It is 12:0:0 AM.
It has been 1 days since the epoch.