-1

Need to format time into a readable format like: input:

print(uptime) 21 days, 7:35:25.686738

desired output: 21 days, 7 hours

1 Answers1

1

You could try something like this:

date_str = str(uptime)
days, times = date_str.split(", ")
result = days
times = times.split(":")
units = ["hours", "minutes", "seconds"]
for i, unit in enumerate(units):
    result += f", {times[i]} {unit}"
print(result)

Basically, I'm constructing the string manually here.

Dilith Jayakody
  • 136
  • 1
  • 5