v04 update 03

This commit is contained in:
13339479676 2022-01-20 18:36:50 +08:00
parent 9afdeb7e09
commit 0f439e5235
1 changed files with 27 additions and 21 deletions

View File

@ -1,28 +1,34 @@
# 时间格式化
# 创建人:曾逸夫
# 创建时间2022-01-19
# # 时间格式化
# # 创建人:曾逸夫
# # 创建时间2022-01-19
import sys
# import sys
def is_time(preTime):
if (preTime <= 0):
print(f'时间格式不正确!程序结束!')
sys.exit()
# def is_time(preTime):
# if (preTime <= 0):
# print(f'时间格式不正确!程序结束!')
# sys.exit()
def time_format(preTime):
is_time(preTime)
m, s = divmod(preTime, 60)
h, m = divmod(m, 60)
time_list = [s, m, h]
time_list = [round(i, 3) for i in time_list]
# print(f'{h}小时{m}分{s}秒')
return f'{time_list[2]}小时{time_list[1]}{time_list[0]}'
# def time_format(preTime):
# is_time(preTime)
# m, s = divmod(preTime, 60)
# h, m = divmod(m, 60)
# s = round(s, 3)
# time_dict = {s:'秒', m:'分', h:'时'}
# aaa = ""
# for k, v in time_dict.items():
# if (k != 0):
# aaa += f'{k}{v} '
# # print(f'{h}小时{m}分{s}秒')
# for i in range(len(time_list)):
# return f'{time_list[2]}小时{time_list[1]}分{time_list[0]}秒'
if __name__ == '__main__':
# time_test = 3600*24 + 1000
time_test = 0.52312
# time_test = 5000
time_format(time_test)
# if __name__ == '__main__':
# # time_test = 3600*24 + 1000
# time_test = 0.52312
# # time_test = 5000
# time_format(time_test)