Timecc++ Time时间的获取与简单操作

来源:互联网 发布:ddo软件官网 编辑:程序博客网 时间:2024/06/14 20:32
#include "stdafx.h"
#include<time.h>
#include<Windows.h>
#include<iostream>
using namespace std;
int main()
{
cout << "秒精确" << endl;
time_t start, end;
start = time(NULL);
Sleep(2000);
end = time(NULL);
printf("time: %f\n", difftime(end, start));


//Sleep的模拟只是一个非常近似的模拟,会有一点误差
cout << "毫秒精确" << endl;
DWORD ds, de;
ds = GetTickCount();
Sleep(3333);
de = GetTickCount();
printf("time: %ld\n", de - ds);


//获取当前日期 当地时间
SYSTEMTIME s;
GetLocalTime(&s);
cout << "Local Date:" << s.wYear << s.wMonth << s.wDay << "    ";
cout << "Time:" << s.wHour << ":" << s.wMinute << ":" << s.wSecond << endl;


//获取当前日期 UTC时间
GetSystemTime(&s);
cout << "UTC Date:  " << s.wYear << s.wMonth << s.wDay << "    ";
cout << "Time:" << s.wHour << ":" << s.wMinute << ":" << s.wSecond << endl;

}


阅读全文
0 0
原创粉丝点击