Python中的十进制时间 [英] Time to decimal time in Python

查看:30
本文介绍了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)

这篇关于Python中的十进制时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆