精确到秒
#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
这篇博客介绍了如何在C++中使用<sys/time.h>和<sys/timeb.h>头文件获取当前时间,分别精确到秒和毫秒。示例代码展示了如何通过time()函数获取整秒时间,并通过ftime()函数获取包含毫秒的时间戳。
&spm=1001.2101.3001.5002&articleId=128492734&d=1&t=3&u=e1473210d0304e649729a535b2d68a74)
1万+

被折叠的 条评论
为什么被折叠?



