Python中的十进制时间

问题描述:

我应该使用哪种 Python 日期时间或时间方法将 HH:MM:SS 中的时间转换为以秒为单位的十进制时间?时间代表时间的持续时间(大多数小于一分钟)并且与日期无关.

Which Python datetime or time method should I use to convert time in HH:MM:SS to decimal time in seconds? The times represent durations of time (most are less than a minute) and are not connected to a date.

t = "1:12:23"
(h, m, s) = t.split(':')
result = int(h) * 3600 + int(m) * 60 + int(s)