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}")
07-01
7121
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-10
1283
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-01
3647
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-25
1361
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-10
2044
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-11
8163
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)