#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 <<":"<<s.wMilliseconds<< endl;
//获取当前日期 UTC时间
GetSystemTime(&s);
cout << "UTC Date: " << s.wYear << s.wMonth << s.wDay << " ";
cout << "Time:" << s.wHour << ":" << s.wMinute << ":" << s.wSecond <<":" s.wMilliseconds<<endl;
#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 <<":"<<s.wMilliseconds<< endl;
//获取当前日期 UTC时间
GetSystemTime(&s);
cout << "UTC Date: " << s.wYear << s.wMonth << s.wDay << " ";
cout << "Time:" << s.wHour << ":" << s.wMinute << ":" << s.wSecond <<":" s.wMilliseconds<<endl;
}