人性化转化时间显示的单位 - xd21303/Notebook GitHub Wiki
def humanized_time(time_in_seconds):
"""
人性化转化时间显示的单位
"""
day = 24*60*60
hour = 60*60
min = 60
if time_in_seconds < 60:
return f"{math.ceil(time_in_seconds)}秒"
elif time_in_seconds > day:
days = divmod(time_in_seconds, day)
return f"{int(days[0])}天{humanized_time(days[1])}"
elif time_in_seconds > hour:
hours = divmod(time_in_seconds, hour)
return f"{int(hours[0])}小时{humanized_time(hours[1])}"
else:
mins = divmod(time_in_seconds, min)
return f"{int(mins[0])}分钟{math.ceil(mins[1])}秒"