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;
Code: Untitled.c Select all
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.
Code: Untitled.c Select all
printf("tv_now.tv_sec %" PRId64 "\n", (int64_t)tv_now.tv_usec);This is the code;
Code: Untitled.c Select all
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.
