首页 > 解决方案 > python: using ctypes.windll.kernel32.GetTickCount64 to get uptime gives negative result

问题描述

I'm trying to get the uptime of a windows machine using ctypes.windll.kernel32.GetTickCount64. I'm not sure what it's giving me though, I thought it was supposed to be the number of ticks since the systems started in milliseconds. It seems to be a negative number which is going down though. I read somewhere that it's an unsigned int, but it seems like a regular int to me.

import ctypes
import time
for _ in range(10):
    print ctypes.windll.kernel32.GetTickCount64()
    time.sleep(1)

-1514476171
-1514475171
-1514474156
-1514473156
-1514472156
-1514471156
-1514470156
-1514469156
-1514468156
-1514467140

How can I convert this value to get an uptime in seconds? Or is there a better way to get this information?

标签: pythonwindowspython-2.7windows-10ctypes

解决方案


推荐阅读