1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| import datetime
def convert_seconds(seconds): """ 将给定的秒数转换为小时、分钟和秒。 """ hour = seconds // 3600 minute = (seconds % 3600) // 60 second = seconds % 60 if hour == 0: if minute == 0: run_time = f"{second} 秒" else: run_time = f"{minute} 分 {second} 秒" else: run_time = f"{hour} 小时 {minute} 分 {second} 秒"
return run_time
def main(): start = datetime.datetime.now() end = datetime.datetime.now()
run_time = convert_seconds((end-start).seconds)
|