gpt4 book ai didi

python - python中的日期时间差异

转载 作者:太空宇宙 更新时间:2023-11-04 10:43:52 25 4
gpt4 key购买 nike

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_timeproc_start_time 是字符串,因为这是 strftime 返回的内容。

您需要摆脱 current_time,并使 proc_start_time = time.localtime(proc.create_time)。现在您有两个时间对象,这将使您能够找到差异。

关于python - python中的日期时间差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18818484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com