1 #include <sys/time.h> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <unistd.h> 5 #include <time.h> 6 main()7int main() 8 { 9 struct timeval *tv = malloc(sizeof(struct timeval)); 10 struct timezone *tz = malloc(sizeof(struct timezone)); 11 for (int i = 0; i < 15; i++) 12 { 13 gettimeofday(tv, NULL); 14 printf("%ld.%06ld\n", tv->tv_sec, tv->tv_usec); 15 for (int i = 0; i < 10; i++) 16 { 17 usleep(500000); 18 } 19 } 20 gettimeofday(tv, NULL); 21 printf("tv = %ld.%06ld\n", tv->tv_sec, tv->tv_usec); 22 // printf("tz_minuteswest = %d,tz_dsttime = %d", (*tz).tz_minuteswest, (*tz).tz_dsttime); 23 return 0; 24 }