電腦開機(jī)時(shí)間的計(jì)算代碼
更新時(shí)間:2013年05月17日 17:09:18 作者:
這幾天我琢磨著一件事,那就是怎么計(jì)算我的PC從開機(jī)到現(xiàn)在的總時(shí)間。終于,看看這個(gè)函數(shù):GetTickCount();
函數(shù)功能:GetTickCount返回(retrieve)從操作系統(tǒng)啟動(dòng)到現(xiàn)在所經(jīng)過(elapsed)的毫秒數(shù),它的返回值是DWORD.
知道了這個(gè),這個(gè)程序也就不是什么難事了。。。
CODE:
復(fù)制代碼 代碼如下:
#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: %s\n",time);
gettime(times); // call gettime()
sleep(1000); // sleep 1 second
printf("已開機(jī)時(shí)間: %02d小時(shí)%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;
}
相關(guān)文章
C/C++通過HTTP實(shí)現(xiàn)文件上傳與下載的示例詳解
WinInet是 Microsoft Windows 操作系統(tǒng)中的一個(gè) API 集,用于提供對(duì) Internet 相關(guān)功能的支持,它包括了一系列的函數(shù),使得 Windows 應(yīng)用程序能夠進(jìn)行網(wǎng)絡(luò)通信、處理 HTTP 請(qǐng)求、FTP 操作等,本文給大家介紹了C/C++通過HTTP實(shí)現(xiàn)文件上傳與下載,需要的朋友可以參考下2023-12-12
淺析結(jié)束程序函數(shù)exit, _exit,atexit的區(qū)別
在一個(gè)程序中最多可以用atexit()注冊(cè)32個(gè)處理函數(shù),這些處理函數(shù)的調(diào)用順序與其注冊(cè)的順序相反,也即最先注冊(cè)的最后調(diào)用,最后注冊(cè)的最先調(diào)用2013-09-09
約瑟夫環(huán)問題(數(shù)組法)c語言實(shí)現(xiàn)
這篇文章主要介紹了約瑟夫環(huán)問題(數(shù)組法)c語言實(shí)現(xiàn),有需要的朋友可以參考一下2013-12-12
C語言利用數(shù)組和文件實(shí)現(xiàn)登錄注冊(cè)功能
這篇文章主要為大家詳細(xì)介紹了C語言利用數(shù)組和文件實(shí)現(xiàn)登錄注冊(cè)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-12-12

