xref: /DragonOS/user/apps/test_gettimeofday/main.c (revision b8ed38251dc255b0c525801b5dbf37d3b0d0d61e)
136fd0130Shoumkh #include <sys/time.h>
236fd0130Shoumkh #include <stdio.h>
336fd0130Shoumkh #include <stdlib.h>
436fd0130Shoumkh // #include <sleep.h>
536fd0130Shoumkh #include <unistd.h>
636fd0130Shoumkh #include <time.h>
736fd0130Shoumkh 
836fd0130Shoumkh int main()
936fd0130Shoumkh {
1036fd0130Shoumkh     struct timeval *tv = malloc(sizeof(struct timeval));
11*b8ed3825SDonkey Kane     struct timezone *tz = malloc(sizeof(struct timezone));
12*b8ed3825SDonkey Kane     for (int i = 0; i < 15; i++)
13*b8ed3825SDonkey Kane     {
14*b8ed3825SDonkey Kane         gettimeofday(tv, NULL);
15*b8ed3825SDonkey Kane         printf("%ld.%06ld\n", tv->tv_sec, tv->tv_usec);
16*b8ed3825SDonkey Kane         for (int i = 0; i < 10; i++)
17*b8ed3825SDonkey Kane         {
18*b8ed3825SDonkey Kane             usleep(500000);
19*b8ed3825SDonkey Kane         }
20*b8ed3825SDonkey Kane     }
2136fd0130Shoumkh     gettimeofday(tv, NULL);
2236fd0130Shoumkh     printf("tv = %ld.%06ld\n", tv->tv_sec, tv->tv_usec);
2336fd0130Shoumkh     // printf("tz_minuteswest = %d,tz_dsttime = %d", (*tz).tz_minuteswest, (*tz).tz_dsttime);
2436fd0130Shoumkh     return 0;
2536fd0130Shoumkh }