Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C TimeVal结构秒和微秒_C - Fatal编程技术网

C TimeVal结构秒和微秒

C TimeVal结构秒和微秒,c,C,如何知道1970年1月1日00:00:00到现在使用timeval之间的秒和微秒数?谢谢 struct timeval { long tv_sec; /*seconds since 1/1/1970*/ long tv_usec; /*microseconds since tv_sec*/ }; 您可以调用gettimeofday() 但是gettimeofday()已经过时,本手册建议改为: 为什么您认为timeval是您问题的解决方案?当您说使用timeval时,您的意思是要将19

如何知道1970年1月1日00:00:00到现在使用timeval之间的秒和微秒数?谢谢

struct timeval {
  long tv_sec; /*seconds since 1/1/1970*/
  long tv_usec; /*microseconds since tv_sec*/
};

您可以调用
gettimeofday()

但是
gettimeofday()
已经过时,本手册建议改为:


为什么您认为
timeval
是您问题的解决方案?当您说使用timeval时,您的意思是要将1970年
的秒/微秒添加到
timeval吗?
struct timespec
的第二个字段是
tv\u nsec
,而不是
tv\u usec
struct timeval tv;
gettimeofday(&tv, NULL);
tv.tv_sec  /* seconds */
tv.tv_usec /* microseconds */
struct timespec tp;
clock_gettime(CLOCK_REALTIME, &tp);
tp.tv_sec  /* seconds */
tp.tv_usec /* nanoseconds divide by 1000 to get microseconds*/