[SOLVED] get timestamp in milliseconds

guillermop
Posts: 12
Joined: Thu Jul 06, 2017 2:52 am

[SOLVED] get timestamp in milliseconds

Postby guillermop » Fri Apr 06, 2018 1:49 am

Hi, I'm following the sntp example to get the unix timestamp but

Code: Select all

time(&now);
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?
Last edited by guillermop on Sat Apr 07, 2018 5:18 am, edited 1 time in total.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: get timestamp in milliseconds

Postby kolban » Fri Apr 06, 2018 4:11 am

Howdy,
Maybe this post might assist?

viewtopic.php?t=2499
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

guillermop
Posts: 12
Joined: Thu Jul 06, 2017 2:52 am

Re: get timestamp in milliseconds

Postby guillermop » Fri Apr 06, 2018 2:24 pm

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

vonnieda
Posts: 145
Joined: Tue Nov 07, 2017 3:42 pm

Re: get timestamp in milliseconds

Postby vonnieda » Fri Apr 06, 2018 2:41 pm

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));
}

guillermop
Posts: 12
Joined: Thu Jul 06, 2017 2:52 am

Re: get timestamp in milliseconds

Postby guillermop » Sat Apr 07, 2018 5:17 am

Thanks vonnieda, it works!

Who is online

Users browsing this forum: No registered users and 59 guests