【发布时间】:2021-05-15 08:10:18
【问题描述】:
String Time
00:51:21,920
Decimal Time
3,081.92 (second)
有没有可以以秒为单位在字符串时间和十进制时间之间转换的方法?我想在moviepy VideoFileClip.subclip中使用它。
以下是我所做的并且有效。但我认为应该有一种更简单的方法,比如库中的函数。
def TrsTime(VideoTime):
return (datetime.strptime(VideoTime, '%H:%M:%S,%f').hour*60*60+
datetime.strptime(VideoTime, '%H:%M:%S,%f').minute*60+
datetime.strptime(VideoTime, '%H:%M:%S,%f').second+
datetime.strptime(VideoTime, '%H:%M:%S,%f').microsecond/1000/1000)
【问题讨论】:
-
您应该添加您尝试过的内容并阅读如何创建minimal reproducible example。
标签: python python-3.x string python-datetime