System time in milliseconds

Hi,

I have been trawling through the internet looking for a platform independent way of getting system time in milliseconds.

Most of my searches just returned the answer that there is no such thing.

Does anyone know of a way in QNX 6.3.2 of getting the system time in milliseconds (or smaller increments)?

Thanks,

David

clock_gettime qnx.com/developers/docs/6.3. … ttime.html

Thanks,

While I was waiting for a response I searched through both time.h files and found this and am now using it.

Here is the function I created:

void print_time()
{

	struct timespec timsp;								// For nanosecond timestamp
	time_t rawtime;										// For localtime
	struct tm * timeinfo;								// For localtime
	char* timeinasc;									// Ascii representation of time
	char outputstring[256];								// Outputted string you can return this or manipulate any way req.

	// Get millisecond timestamp
	if(clock_gettime(CLOCK_REALTIME, &timsp) == -1)
	{
		printf("Error when getting millisecond timestamp error number = %d\n", errno);
	}
	
	// Get localtime
	time(&rawtime);
	timeinfo = localtime(&rawtime);
	timeinasc = asctime(timeinfo);
	
	// Get rid of date a trailing newline character (why add this?)
	timeinasc[strlen(timeinasc)-1] = 0;
	timeinasc[strlen(timeinasc)-2] = 0;
	timeinasc[strlen(timeinasc)-3] = 0;
	sprintf(outputstring, "%s:%d \n",timeinasc, timsp.tv_nsec/1000000);
	printf("%s", outputstring);
}

There may be a small discrepency between the millisecond value and the local time but I do not require that level of accuracy.

Thanks for the response.