1. 使用clock_gettime接口即可

2. clock_gettime的使用方法:

  2.1 定义一个结构体

  struct timespec ts;

  2.2 调用clock_gettime获取当前时间戳

  clock_gettime(CLOCK_MONOTONIC, &ts);

  2.3 打印时间戳

  printf("<%d.%d>\n",ts.tv_sec,ts.tv_nsec);

3. 加上此接口后编译链接时需要加上librt库,因为clock_gettime包含在librt库中

  gcc myprog.c -o myprog -lrt

相关文章:

  • 2021-11-18
  • 2023-03-29
  • 2023-03-29
  • 2022-12-23
  • 2021-07-14
  • 2021-12-05
  • 2023-03-29
  • 2023-03-29
猜你喜欢
  • 2022-01-08
  • 2021-04-25
  • 2021-08-24
  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案