For a tm Strict

Loading current time into a tm struct – see here

Get The Current Time And Display In A String


#include <sys/time.h>

	static int seconds_last = 99;
	char TimeString[128];

	timeval curTime;
	gettimeofday(&curTime, NULL);
	if (seconds_last == curTime.tv_sec)
		return;
	
	seconds_last = curTime.tv_sec;
	
	strftime(TimeString, 80, "%Y-%m-%d %H:%M:%S", localtime(&curTime.tv_sec));

 

timeval and gettimeofday gives you tvsec and tv_usec which is the number of seconds the  Epoch.  You need to use local time to convert into the current time.