2 回答
TA贡献1801条经验 获得超8个赞
我认为 python 时间模块可以提供帮助
import time
a = "00:00:00 1971"
a = time.mktime(time.strptime(a,"%H:%M:%S %Y"))
ClockTime1 = input('Enter clock two timie (in military time) in the format HH:MM:SS ,
it has to be in this format in order to function correctly :')
ClockTime2= input('Enter clock one time (in military time) in the format HH:MM:SS ,
it has to be in this format in order to function correctly :')
ClockTime1+=" 1971"
ClockTime2+=" 1971"
ClockTime1 = time.mktime(time.strptime(ClockTime1,"%H:%M:%S %Y"))
ClockTime2 = time.mktime(time.strptime(ClockTime2,"%H:%M:%S %Y"))
print(time.strftime("%H:%M:%S", time.localtime(ClockTime1-a+ClockTime2-a+a)))
TA贡献1836条经验 获得超4个赞
我认为我们可以使用一些内置的日期时间函数,而不是自己计算它们:
from datetime import datetime,timedelta
str_t1="23:00:01"
str_t2="23:00:01"
dt1 = datetime.strptime(str_t1, '%H:%M:%S')
dt2 = datetime.strptime(str_t2, '%H:%M:%S')
dt2_delta=timedelta(hours=dt2.hour, minutes=dt2.minute, seconds=dt2.second)
dt3=dt1+dt2_delta
str_t3=datetime.strftime(dt3,'%H:%M:%S')
str_t3 的输出是:
str_t3 '22:00:02'
添加回答
举报