import datetime
time = datetime.datetime.strptime("07:12:54", "%H:%M:%S") # suppose that the time is 07:12:54
print(time.strftime ("%H:%M:%S"))
delta = datetime.timedelta(seconds=2000.234) # I need to add 2000.234 seconds
print(delta)
new_time = time + delta # calculate the output time in HH:MM:SS
print(new_time.strftime ("%H:%M:%S"))
new_time2 = time - delta # decrease the seconds of the HH:MM:SS time
print(new_time2.strftime ("%H:%M:%S"))
1条答案
按热度按时间nwlqm0z11#
最简单的方法应该是将datetime与timedelta一起使用:
导致输出: