main.c 641 B

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