手机
当前位置:查字典教程网 >编程开发 >C语言 >电脑开机时间的计算代码
电脑开机时间的计算代码
摘要:函数功能:GetTickCount返回(retrieve)从操作系统启动到现在所经过(elapsed)的毫秒数,它的返回值是DWORD.知道...

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

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

CODE:

复制代码 代码如下:

#include <stdlib.h>

#include <time.h>

#include <windows.h>

#include <stdio.h>

typedef struct node

{

int h;

int m;

int s;

}

*PTime;

void sleep(long wait);

void gettime();

int main()

{

PTime times;

int flag = 1;

char time[128];

do

{

_strtime(time); // Gets the current system time (do not include the date)

system("cls"); // clear screen

printf("OS time: %sn",time);

gettime(times); // call gettime()

sleep(1000); // sleep 1 second

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

}while(flag); // always cycle

return 0;

}

void sleep(long wait)

{

long goal; // define total time

goal = wait + clock();

while(goal > clock());

}

PTime gettime(PTime T)

{

int i = GetTickCount();

T->h = (i / 1000) / 3600;

T->m = (i / 1000) / 60 - T->h * 60;

T->s = (i / 1000) - T->h * 3600 - T->m * 60;

return T;

}

【电脑开机时间的计算代码】相关文章:

c语言全盘搜索指定文件的实例代码

基于C/C++时间函数的使用详解

二分法求多项式在-10 10间值的实现代码

解析四则表达式的编译过程及生成汇编代码

归并排序的递归实现与非递归实现代码

C连接Mysql数据库代码

哈夫曼的c语言实现代码

用C++实现队列的程序代码

C++中获取UTC时间精确到微秒的实现代码

求子数组最大和的实例代码

精品推荐
分类导航