我提到了一个多级字典,其中包含各种事件的各种时间。这是我想要减去两个保存事件的代码,用于计算它们之间的差异:
{'eventtime':
{'6': {'keypressevent': '14:08:33:806443', 'eventdestroytime': '14:08:35:144520', 'systemtime': '14:08:29:143176', 'keyreleaseevent': '14:08:38:574716'},
'7': {'keypressevent': '14:08:02:318642', 'eventdestroytime': '14:08:02:025625', 'systemtime': '14:07:55:025225', 'keyreleaseevent': '14:08:05:590829'},
'5': {'keypressevent': '14:08:22:198779', 'eventdestroytime': '14:08:21:855759', 'systemtime': '14:08:16:854473', 'keyreleaseevent': '14:08:27:143062'},
'3': {'keypressevent': '14:08:10:919134', 'eventdestroytime': '14:08:10:592115', 'systemtime': '14:08:07:590944', 'keyreleaseevent': '14:08:14:854359'}
},
'userinfo': {'gender': 'm', 'usercode': 'TY123', 'weight': '65', 'age': '26', 'event': 'r', 'height': '165'}}
虽然我使用下面的strptime转换时间用于循环。我输错了时间格式:
for ct in self.reproductioninfo['eventtime']:
print(datetime.strptime(self.reproductioninfo['eventtime'][ct]['keypressevent'], '%H:%M:%S:%f'))
输出是:错误
1900-01-01 14:08:33.806443
1900-01-01 14:08:02.318642
1900-01-01 14:08:22.198779
1900-01-01 14:08:10.919134
输出应为:
14:08:33.806443
14:08:02.318642
14:08:22.198779
14:08:10.919134
我想减去那个时间但是减去
错误是: datetime.time()不支持操作数
答案 0 :(得分:0)
strptime
返回git config http.postBuffer 524288000
个实例,包括年,月和日。如果您未在输入中提供这些内容,则会datetime
。
比较两个1900-01-01
个实例,也可以使用datetime
打印它们。
strftime
输出:
import datetime
format = "%H:%M:%S:%f"
d1 = "14:08:33:806443"
d2 = "14:08:02:318642"
p1 = datetime.datetime.strptime(d1, format)
p2 = datetime.datetime.strptime(d2, format)
print(p1 > p2)
print(p1.strftime(format))
print(p2.strftime(format))
print(p1 - p2)