擅长:python、mysql、java
<p>你需要做一些转换。我会把你的值转换成整数。如果minutes大于59,则将其添加到hours。之后,我们可以创建一个datetime对象,用它进行减法运算。为了得到分钟数,我们以秒为单位,将其除以60</p>
<pre class="lang-py prettyprint-override"><code>from datetime import datetime
def to_time(value):
"Takes in values as '%M:%S' and return datetime object"
# value casting to integers
minutes, seconds = [int(i) for i in value.split(':')]
# if minutes is greater than 59 pass it to hour
hour = 0
if minutes > 59:
hour = minutes//60
minutes = minutes%60
return datetime.strptime(f'{hour}:{minutes}:{seconds}', '%H:%M:%S')
# now our calculations
wrong_index = '60:01'
new_index = '00:02'
time_ = to_time(wrong_index) - to_time(new_index)
print(time_.seconds/60)
</code></pre>