我们如何知道自从我们按下计算机上的电源按钮后已经有多长时间了?

时间:2017-10-17 16:20:47

标签: c++ c windows winapi

我尝试了Windows API函数,但我不明白哪一个符合我的要求。与GetTickCount64QueryInterruptTime等相同。如何计算?

2 个答案:

答案 0 :(得分:0)

GetTickCount64返回自上次启动以来的毫秒数。这应该足够了。

答案 1 :(得分:-2)

enter image description here

您也可以使用GetTickCount()。像这样:

#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;
}