Python:将 snmp timeticks 转换为 seconds/days,等等

Python: convert snmp timeticks to seconds/days, etc

我正在使用 pysnmp 对一些网络设备进行 SNMP 轮询。正常运行时间作为 timeticks 值返回,即 1/100 秒。如何将时间标记转换为 days/hours/seconds 等?

DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (197740964) 22 days, 21:16:49.64

找到我自己的答案。

>>> ticks = 197740964
>>> seconds = ticks/100
>>> datetime.timedelta(seconds=seconds)
datetime.timedelta(22, 76609)
>>> print datetime.timedelta(seconds=seconds)
22 days, 21:16:49

根据上面的回答,Python 对我有用的代码: (第 [6] 行包含 TimeTicks)

from datetime import datetime, timedelta
ticks = int(row[6])
seconds = ticks/100
up_time = timedelta(seconds=seconds)
print(row[1], ": ",  up_time)