计算开机时间c语言编程,计算电脑开机时间的代码

今天爱站小编将为大家详细介绍计算电脑开机时间的代码,相信很多小伙伴都非常好奇且想要学习的,那么下面就跟爱站小编一起去学习吧。

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

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

CODE:

#include #include #include #include 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: %s\n",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语言的相关知识还很多,以后要多在实战项目中运用才能更好地体会。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值