精确到秒
#include <iostream>
#include <sys/time.h>
using namespace std;
int main(){
time_t t=time(NULL);
printf("time:%d\n",t);
return 0;
}
精确到毫秒
#include <iostream>
#include <sys/timeb.h>
using namespace std;
int main(){
timeb t;
ftime(&t);
printf("time:%d\n", (t.time * 1000 + t.millitm));
return 0;
}
参考资料:
https://blog.csdn.net/weixin_44757097/article/details/106081332
https://blog.csdn.net/weixin_34163553/article/details/92473595