Эта функция возвращает время из наносекунд в часы минуты секунды милесекунды:
def convert_time(t):
s, ns = divmod(t, 1000000000)
m, s = divmod(s, 60)
end_res = ['00:', '00:', '00:', '00']
res = ''
if m < 60:
if len(str(m)) < 2:
end_res[1] = '0'+str(m)+':'
else:
end_res[1] = str(m)+':'
if len(str(s)) < 2:
end_res[2] = '0'+str(s)+':'
else:
end_res[2] = str(s)+':'
try:
end_res[3] = str(round(ns/1000000000))
except IndexError:
end_res[3] = '00'
else:
h, m = divmod(m, 60)
if len(str(h)) < 2:
end_res[0] = '0'+str(h)+':'
else:
end_res[0] = str(h)+':'
if len(str(m)) < 2:
end_res[1] = '0'+str(m)+':'
else:
end_res[1] = str(m)+':'
if len(str(s)) < 2:
end_res[2] = '0'+str(s)+':'
else:
end_res[2] = str(s)+':'
end_res[3] = str(round(ns/1000000000))
for x in range(0, 4):
res += end_res[x]
print(res)
Желаемый вывод
list ['00:','00:','00:','00:']
Возможно ли её улучшить, или быть может есть стандартные билиотеки для такой реализации.