时间戳,秒级
测试代码:
#include <iostream>
#include <time.h>
#include <windows.h>
using namespace std;
int main()
{
//------当前的时间戳(秒)--------
time_t t;
time(&t);
cout << t << endl;
Sleep(1200);
time(&t);
cout << t << endl;
system("pause");
return 0;
}
结果:
时间戳,毫秒级
测试代码:
#include <iostream>
#include<sys/timeb.h>
using namespace std;
long long systemtime()
{
timeb t;
ftime(&t);
return t.time * 1000 + t.millitm;
}
int main()
{
//------当前的时间戳(豪秒)--------
while (1)
{
long long timeA = systemtime();
cout << timeA << endl; //system("cls");
}
system("pause");
return 0;
}
结果:
毫秒级时间间隔
测试代码:
#include <iostream>
#include<time.h>
#include <windows.h>
using namespace std;
int main()
{
//------时间间隔(豪秒)--------
clock_t start, end;
start = clock();
Sleep(50); //windows API 毫秒
end = clock();
cout << end - start << "毫秒" << endl;
system("pause");
return 0;
}
结果:
(注意:结果有误差)
相关博客:【C++】获取当前的日期和时间(多种格式)
原文链接: https://www.cnblogs.com/KMould/p/14898286.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/211477
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!