我正在使用pysnmp对某些网络设备进行SNMP轮询。正常运行时间以timeticks值的形式返回,即1/100秒。你如何将时间戳转换为天/小时/秒等?
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (197740964) 22 days, 21:16:49.64
答案 0 :(得分:5)
找到我自己的答案。
>>> ticks = 197740964
>>> seconds = ticks/100
>>> datetime.timedelta(seconds=seconds)
datetime.timedelta(22, 76609)
>>> print datetime.timedelta(seconds=seconds)
22 days, 21:16:49
答案 1 :(得分:0)
从以上答案中,对我有用的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)