def lastTime(t):
s = ""
days_s = ""
hour_s = ""
min_s = ""
sec = t
while True:
if sec <= 60:
second_s =str(sec)
if days_s != "":
s = days_s +"天"
if hour_s != "":
s =s+ hour_s +"小时"
if min_s != "":
s =s+ min_s +"分钟"
s = s + second_s +"秒"
return s
if sec >= 60 and sec<3600:
minutes = sec // 60
min_s =str(minutes)
if sec % 60 ==0:
if days_s != "":
s = days_s +"天"
if hour_s != "":
s =s+ hour_s +"小时"
if min_s != "":
s =s+ min_s +"分钟"
return s
else:
sec = sec % 60
if sec >= 3600 and sec<86400:
# global sec, hour_s
hours = sec // 3600
hour_s = str(hours)
if sec % 3600 ==0:
if days_s != "":
s = days_s + "天"
if hour_s != "":
s = s + hour_s + "小时"
return s
else:
sec = sec % 3600
if sec >= 86400:
days = sec // 86400
days_s = str(days)
if sec % 86400 ==0:
return days
else:
sec = sec % 86400
# print('The number of minutes is {0:.2f}'.format(days))
print(lastTime(24*3600+67+3*3600))
运行
F:\pyinstaller-g2\venv\Scripts\python.exe F:/pyinstaller-g2/stf.py
1天3小时1分钟7秒
Process finished with exit code 0