我有两次字符串格式HHMM,我想在几分钟内找到差异。
我已经尝试过以下但我收到以下错误:
TypeError:不支持的操作数类型 - :' datetime.time'和' datetime.time'
import datetime
a = "0628"
b = "0728"
aSep = a[:2] + ':' + a[2:]
bSep = b[:2] + ':' + b[2:]
timeA = datetime.datetime.strptime(aSep, '%H:%M').time()
timeB = datetime.datetime.strptime(bSep, '%H:%M').time()
diff = timeB -timeA
print diff
答案 0 :(得分:2)
import datetime
a = "0628"
b = "0728"
timeA = datetime.datetime.strptime(a, "%H%M")
timeB = datetime.datetime.strptime(b, "%H%M")
print((timeB-timeA).total_seconds())
print(((timeB-timeA).total_seconds()/60.0))
<强>输出:强>
3600.0
60.0