test_gettimeofday.c 596 B

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