Page 1 of 1
[SOLVED] get timestamp in milliseconds
Posted: Fri Apr 06, 2018 1:49 am
by guillermop
Hi, I'm following the
sntp example to get the unix timestamp but
return the timestamp in seconds and I'd like to get it in milliseconds, I haven't found a function to do that, there is currently any way to achive that?
Re: get timestamp in milliseconds
Posted: Fri Apr 06, 2018 4:11 am
by kolban
Howdy,
Maybe this post might assist?
viewtopic.php?t=2499
Re: get timestamp in milliseconds
Posted: Fri Apr 06, 2018 2:24 pm
by guillermop
Thanks kolban,
The problem is xTaskGetTickCount and getTimeSinceStart will return the time passed since the device was turned on, but I'm looking for the date time output. I think it's possible to make something with time and getTimeSinceStart but I suppose I'll lose some precision, if there is not other way it's what I'll do
Re: get timestamp in milliseconds
Posted: Fri Apr 06, 2018 2:41 pm
by vonnieda
guillermop wrote:Thanks kolban,
The problem is xTaskGetTickCount and getTimeSinceStart will return the time passed since the device was turned on, but I'm looking for the date time output. I think it's possible to make something with time and getTimeSinceStart but I suppose I'll lose some precision, if there is not other way it's what I'll do
Code: Select all
int64_t xx_time_get_time() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (tv.tv_sec * 1000LL + (tv.tv_usec / 1000LL));
}
Re: get timestamp in milliseconds
Posted: Sat Apr 07, 2018 5:17 am
by guillermop
Thanks vonnieda, it works!