Currently viewing: GipsySoft » Front Page» Articles

How can get the elapsed time between two SYSTEMTIME structures.

Basically you convert the SYSTEMTIMEs to FILETIMEs, convert them to ULARGE_INTEGERs and then subtract one from the other .

Here is some sample code that does just that.

	SYSTEMTIME st1, st2;
	GetSystemTime( &st1 );
	Sleep( 1000 );
	GetSystemTime( &st2 );

	FILETIME ft1, ft2;
	SystemTimeToFileTime( &st1, &ft1 );
	SystemTimeToFileTime( &st2, &ft2 );
	ULARGE_INTEGER u1, u2;
	u1.LowPart = ft1.dwLowDateTime;
	u1.HighPart = ft1.dwHighDateTime;
	u2.LowPart = ft2.dwLowDateTime;
	u2.HighPart = ft2.dwHighDateTime;

	ULARGE_INTEGER u3;
	u3.QuadPart = u2.QuadPart - u1.QuadPart;
	printf( "%d seconds difference\n", u3.QuadPart/10000000 );