do_gettimeofday使用方法

1.簡介:

在Linux中可使用函數do_gettimeofday()函數來獲得精確時間。它的精度能夠達到微妙,是與C標準庫中gettimeofday()用發相同的函數。在Linux內核中得到時間的函數。linux

2.函數原型:

#include <linux/time.h> 

void do_gettimeofday(struct timeval *tv);

3.說明:

do_gettimeofday()會把目前的時間用tv 結構體返回,當地時區的信息則放到tz所指的結構中函數

4.結構體:

1. timeval 結構體定義:spa

struct timeval { 

  time_t tv_sec; /* seconds */
 
  suseconds_t tv_usec; /* microseconds */ 

};

 

5.例code

struct timeval tv_begin,tv_end; do_gettimeofday(&tv_begin,NULL); sleep(5); do_gettimeofday(&tv_end,NULL); printf(「tv_begin_sec:%d\n」,tv_begin.tv_sec); printf(「tv_begin_usec:%d\n」,tv_begin.tv_usec); printf(「tv_end_sec:%d\n」,tv_end.tv_sec); printf(「tv_end_usec:%d\n」,tv_end.tv_usec);
相關文章
相關標籤/搜索