当前位置:
首页 >
clock_gettime获取时间
发布时间:2025/6/15
35
豆豆
生活随笔
收集整理的这篇文章主要介绍了
clock_gettime获取时间
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
❤️强烈推荐人工智能学习网站❤️
linux下clock_getting可以用来获取时间并精度到纳秒,其中需要用到struct timespec结构体,struct timespec结构体如下:
struct timespec {time_t tv_sec;long tv_nsec; }
写个小程序测试一下:
编译运行:
[mapan@localhost thread]$ gcc -lrt time1.c [mapan@localhost thread]$ ./a.out tv_sec=1509774203,tv_nsec=413767266 [mapan@localhost thread]$
linux下还有其他的时间结构体,但是struct timespec可以精确到纳秒。
总结
以上是生活随笔为你收集整理的clock_gettime获取时间的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 利用curl命令测试服务端
- 下一篇: rand和srand