python - python中的日期时间差异

标签 python datetime

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/

相关文章:

python - 如何在 matplotlib 中将数字转换为色标?

python - 非常嘈杂信号的 Scipy FFT 频率分析

python - 获取 2D 网格中每个 bin 的中值

c# - 想根据输入的数字查找日期 C#

python QThread.run 参数 - 版本之间发生变化?

python - 为什么不能在 python 中异或字节对象?

python - 为什么这个 Sqlite 日期比较有效?

php - 在 PHP 中转换日期格式(但这是什么格式?)

javascript - YouTube Live Streaming API 'scheduledStartTime' 向观众显示错误的时区

sql - PostgreSQL - 其中日期时间 <= YEAR-MONTH-DAY,忽略时间