for proc in psutil.process_iter():
if proc.name == "monit":
current_time = time.localtime()
proc_start_time = time.localtime(proc.create_time)
print (current_time - proc_start_time).seconds
我无法找到两个日期时间之间的差异。不能减去它们给出错误 -
TypeError:不支持的操作数类型 -:'time.struct_time' 和 'time.struct_time'
最佳答案
current_time
和 proc_start_time
是字符串,因为这是 strftime
返回的内容。
您需要摆脱 current_time
,并使 proc_start_time = time.localtime(proc.create_time)
。现在您有两个时间对象,这将使您能够找到差异。
关于python - python中的日期时间差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18818484/