参考
https://blog.csdn.net/weixin_40012554/article/details/108757642
实例
可以实现时间戳直接相减的函数与类型是这个:
b=datetime.strptime(‘12:11:06.178272’,‘%H:%M:%S.%f’) ### %f是微秒
a=datetime.strptime(‘12:11:06.168272’,‘%H:%M:%S.%f’)
b-a
datetime.timedelta(0, 0, 10000)
print(b-a)
0:00:00.010000
code
import sys
import os
import datetime as dt
#for aFile in filelist:
f_trace = open(sys.argv[1],'r')
a=dt.datetime.strptime('0:0:0.000000','%H:%M:%S.%f')
b=dt.datetime.strptime('0:0:0.060000','%H:%M:%S.%f')
time=dt.datetime.strptime('0:0:0.178272','%H:%M:%S.%f')
for line in f_trace:
#f_message.write(line);
#if len(line)!=1: ###if the line is empty
if line.find("fa:16:3e:f1:a3:42")>-1:
time1=dt.datetime.strptime(line.split(" ")[0],'%H:%M:%S.%f')
c=time1-time
if c > (b-a):
print(line)
time=time1
#print(mem)
f_trace.close()
时间戳运算实践
本文介绍了一种使用Python datetime模块进行时间戳运算的方法。通过具体实例展示了如何解析带有微秒的时间字符串,并进行了时间戳的相减操作,从而计算出两个时间点之间的间隔。
6783

被折叠的 条评论
为什么被折叠?



