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