struct timeval{ long int tv_sec; // 秒數 同time(NULL) 的返回值 long int tv_usec; // 微秒數 10 的6次方 };
1 struct timezone{ 2 int tz_minuteswest;/*格林威治時間往西方的時差*/ 3 int tz_dsttime;/*DST 時間的修正方式*/ 4 };
1 #include <stdio.h> 2 #include <sys/time.h> 3 4 int main() 5 { 6 struct timeval tv; 7 struct timezone tz; 8 9 int res = gettimeofday(&tv, &tz); 10 printf("res = %d\n", res); 11 printf("tv.tv_sec = %ld, tv.tv_usec = %ld\n", 12 tv.tv_sec, tv.tv_usec); 13 14 return 0; 15 }