-5

I tried the Windows API functions, but I did not understand which one meets my request. Like GetTickCount64, QueryInterruptTime etc. How can I calculate it?

glennsl
  • 28,186
  • 12
  • 57
  • 75
As As
  • 1
  • 2
  • I always use the duration from the network adapter. Maybe you can get that? – NathanOliver Oct 17 '17 at 16:22
  • 3
    Possible duplicate of [Programmatically getting system boot up time in c++ (windows)](https://stackoverflow.com/questions/10853985/programmatically-getting-system-boot-up-time-in-c-windows) – ZerosAndOnes Oct 17 '17 at 16:29
  • Are you really sure you need something as specific as "time since power button was pressed" rather than something more sensible like "time since last boot"? – glennsl Oct 17 '17 at 16:32
  • There is no way for you to determine the last time the power button was pressed. For all we know, a machine may not even have a power button. If you meant to ask a different question, [edit](https://stackoverflow.com/posts/46794795/edit) it. – IInspectable Oct 17 '17 at 17:02

2 Answers2

0

GetTickCount64 returns the number of milliseconds since the last boot. This should be enough.

roalz
  • 2,699
  • 3
  • 25
  • 42
8znr
  • 336
  • 3
  • 13
-2

enter image description here

You can also use GetTickCount(). Like this:

#include <Windows.h>
#include <stdio.h>

int main(){

    int hours;
    int min;
    int sec;
    int rem1;

    int nSysUpTime = GetTickCount() / 1000;
    int days = nSysUpTime / 60 / 60 / 24;
    hours = nSysUpTime / 3600;
    rem1 = nSysUpTime % 3600;
    min = rem1 / 60;
    sec = rem1 % 60;


    printf( "\nComputer Uptime   %02d:%02d:%02d \n\n",hours , min  ,sec  );


return 0;
}
Software_Designer
  • 8,490
  • 3
  • 24
  • 28
  • 2
    `GetTickCount()` wraps back to 0 every 49.7 days of continuous running. A computer may run much longer than that. Use `GetTickCount64()` instead. – Remy Lebeau Oct 18 '17 at 14:54