python - Getting startup time in Windows 10 doesn't give always the same time -


i'm using python (3.5) code check windows startup time gives me different time time using shell command "systeminfo"

  • systeminfo: 9:15:23
  • python code: 9:14:42

not happy that, python code giving different times in itself! started giving me 9:14:42, , right gives me 9:15:19, it's been adding second boot time every 10 seconds or so.

i give code:

import datetime import win32api  s = win32api.gettickcount() t = datetime.datetime.now() st = datetime.timedelta(milliseconds=s) bt = t-st boot = "boot time around {}:{}:{}".format(bt.hour, bt.minute, bt.second) print(boot) 

i'm starting think calling systeminfo command python , show time gives me.

taken comments , question edit

gettickcount not report startup time. should using wmi

import datetime import wmi  wmiob = wmi.wmi() sdata = wmiob.win32_perfformatteddata_perfos_system() uptime = sdata[-1].systemuptime tnow = datetime.datetime.now() utime = datetime.timedelta(seconds=int(uptime)) boot = tnow-utime bootime = "boot time around {}:{}:{}".format(boot.hour, boot.minute, boot.second) print(bootime) 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -