Python 计算时间差 dateutil.parser库

from dateutil.parser import parse


time_1 = "15:00:00"
time_2 = "18:40:00"

a = parse(time_1)  # 对日期进行格式化
b = parse(time_2)
seconds = (b - a).seconds
m, s = divmod(seconds, 60)  # Return the tuple (x//y, x%y)
h, m = divmod(m, 60)
print(f"{h}:{m:02}:{s:02}")

你可能感兴趣的:(python)