【发布时间】:2021-04-29 17:10:53
【问题描述】:
我提取了一个包含电影时间的字符串
2 小时 28 分钟
我想将时间转换为分钟 (2*60+28)
这是我的方法,但我正在寻找一种更简单的方法
ar = time.split()
def split(word):
return [char for char in word]
if 'h' in ar[0]:
word = ar[0]
sp = split(word)
hours = int(sp[0]) * 60
mins = re.findall(r'\d+', ar[1])
time = hours + int(mins[0])
else:
mins = re.findall(r'\d+', ar[0])
time = int(mins[0])
【问题讨论】:
-
你试过什么?请提供MWE
标签: python python-3.x time