gettimeofday not working with timeval [IDFGH-3263]
Posted: Thu May 07, 2020 9:44 am
Hi guys,
I have a problem with getting time. I need to get the current time in millisecond resolution.
I know that gettimeofday can get in microsecond resolution based on:
https://docs.espressif.com/projects/esp ... _time.html
I am using;
time_us 2806483326588896768
after 10 sec;
time_us 2961102149255896768
there is no sense between them,
also "tv_now.tv_usec" always 0 no mether what.
This is the code;
And this is the serial monitor output for the code above:
tv_now.tv_sec 1588757091
PRId64 tv_now.tv_sec 39854590296675
tv_now.tv_usec 0
time_us 2961102149255896768
I am an amateur with all this,
Thank you all for helping me.
I have a problem with getting time. I need to get the current time in millisecond resolution.
I know that gettimeofday can get in microsecond resolution based on:
https://docs.espressif.com/projects/esp ... _time.html
I am using;
- struct timeval tv_now;
- gettimeofday(&tv_now, NULL);
- int64_t time_us = (int64_t)tv_now.tv_sec * 1000000L + (int64_t)tv_now.tv_usec;
- printf("time_us %" PRId64 "\n", time_us);
after 10 sec;
time_us 2961102149255896768
there is no sense between them,
also "tv_now.tv_usec" always 0 no mether what.
- printf("tv_now.tv_sec %" PRId64 "\n", (int64_t)tv_now.tv_usec);
This is the code;
- struct timeval tv_now;
- gettimeofday(&tv_now, NULL);
- int64_t time_us = (int64_t)tv_now.tv_sec * 1000000L + (int64_t)tv_now.tv_usec;
- printf("tv_now.tv_sec %ld\n", (long)tv_now.tv_sec);
- printf("PRId64 tv_now.tv_sec %" PRId64 "\n", (int64_t)tv_now.tv_sec);
- printf("tv_now.tv_usec %" PRId64 "\n", (int64_t)tv_now.tv_usec);
- printf("time_us %" PRId64 "\n", time_us);
tv_now.tv_sec 1588757091
PRId64 tv_now.tv_sec 39854590296675
tv_now.tv_usec 0
time_us 2961102149255896768
I am an amateur with all this,
Thank you all for helping me.