获取系统开机时间

来源:互联网 发布:巨人网络借壳参与企业 编辑:程序博客网 时间:2024/04/28 01:56

#include <stdio.h>
#include<ctime>
#include <windows.h>
using namespace std;

int main() {

    time_t now;
    struct tm when;
    int tcount = GetTickCount();
    time(&now);
    when = *localtime(&now);
    printf("现在时间为:%d年%d月%d日 %d:%d:%d/n", when.tm_year + 1900, when.tm_mon + 1,
            when.tm_mday, when.tm_hour, when.tm_min, when.tm_sec);
    now -= tcount / 1000;
    when = *localtime(&now);
    printf("开机时间为:%d年%d月%d日 %d:%d:%d/n", when.tm_year + 1900, when.tm_mon + 1,
            when.tm_mday, when.tm_hour, when.tm_min, when.tm_sec);

    DWORD dwStart = GetTickCount();
    printf("%d/n", dwStart);
    printf("已开机时间为 :%d天%d小时%d分钟%d秒/n", dwStart / (1000* 60* 60* 24 ) , dwStart%(1000*60*60*24)/(1000*60*60),dwStart%(1000*60*60*24)%(1000*60*60)/(1000*60),dwStart%(1000*60*60*24)%(1000*60*60)%(1000*60)/(1000));
    return 0;

}

 

参考资料

如何在 C++ 程序中计算时间http://blog.csdn.net/linsi/archive/2010/04/22/5517210.aspx

原创粉丝点击