zl程序教程

您现在的位置是:首页 >  其他

当前栏目

电脑开机时间的计算代码

电脑计算代码 时间 开机
2023-06-13 09:14:54 时间

函数功能:GetTickCount返回(retrieve)从操作系统启动到现在所经过(elapsed)的毫秒数,它的返回值是DWORD.

知道了这个,这个程序也就不是什么难事了。。。

CODE:

复制代码代码如下:


#include<stdlib.h>
 #include<time.h>
 #include<windows.h>
 #include<stdio.h>

 typedefstructnode
 {
    inth;
    intm;
    ints;
 }
 *PTime;

 voidsleep(longwait);

 voidgettime();

 intmain()
 {
    PTimetimes;
    intflag=1;
    chartime[128];
    do
    {
        _strtime(time);//Getsthecurrentsystemtime(donotincludethedate)
        system("cls");//clearscreen
        printf("OStime:%s\n",time);

        gettime(times);//callgettime()
        sleep(1000);//sleep1second

        printf("已开机时间:%02d小时%02d分%02d秒\n",times->h,times->m,times->s);
    }while(flag);//alwayscycle

    return0;
 }

 voidsleep(longwait)
 {
    longgoal;//definetotaltime
    goal=wait+clock();
    while(goal>clock());
 }

 PTimegettime(PTimeT)
 {
    inti=GetTickCount();
    T->h=(i/1000)/3600;
    T->m=(i/1000)/60-T->h*60;
    T->s=(i/1000)-T->h*3600-T->m*60;
    returnT;
 }