The _ftime function does not have a real great resolution, as domonstrated by this little test:
#include <stdio.h>
#include <sys/timeb.h>
#include <time.h>
void main()
{
struct _timeb timebuffer;
char *timeline;
for (int j=0; j< 100; j++ ) {
_ftime( &timebuffer );
timeline = ctime( & ( timebuffer.time ) );
printf( "The time is %.19s.%hu %s", timeline, timebuffer.millitm, &timeline[20] );
}
}
-==-=-=-=-=--==-=-=-=-=-=-
You'll seet a series of times that all have the same milliseconds, then it jumps by 10 or 20 milliseconds, then another series...
As for nanoseconods... forget it. We discussed these issues at length in this thread:
http://www.experts-exchang
In Windows, timeGetTime (the Multimedia timer fn) provides a higher-resolution timer and the QueryPerformanceCounter API provides very high resolution (e.g., for profiling code execution times).
There are a variety of techniques to get a high-resolution timestamp. What is your ultimate goal? Are you just curiuus or do you have a specific need?
-- Dan
Main Topics
Browse All Topics





by: dimitryPosted on 2002-05-20 at 22:43:26ID: 7023263
Take a look at this info from MSDN (you can get also milliseconds):
_ftime - Gets the current time.
void _ftime( struct _timeb *timeptr );
Function Required Header Compatibility
_ftime <sys/types.h> and <sys/timeb.h> Win 95, Win NT
Libraries
LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version
Return Value
_ftime does not return a value, but fills in the fields of the structure pointed to by timeptr.
Parameter
timeptr
Pointer to _timeb structure
Remarks
The _ftime function gets the current local time and stores it in the structure pointed to by timeptr. The _timeb structure is defined in SYS\TIMEB.H. It contains four fields:
dstflag
Nonzero if daylight savings time is currently in effect for the local time zone. (See _tzset for an explanation of how daylight savings time is determined.)
millitm
Fraction of a second in milliseconds.
time
Time in seconds since midnight (00:00:00), January 1, 1970, coordinated universal time (UTC).
timezone
Difference in minutes, moving westward, between UTC and local time. The value of timezone is set from the value of the global variable _timezone (see _tzset).
Example
/* FTIME.C: This program uses _ftime to obtain the current
* time and then stores this time in timebuffer.
*/
#include <stdio.h>
#include <sys/timeb.h>
#include <time.h>
void main( void )
{
struct _timeb timebuffer;
char *timeline;
_ftime( &timebuffer );
timeline = ctime( & ( timebuffer.time ) );
printf( "The time is %.19s.%hu %s", timeline, timebuffer.millitm, &timeline[20] );
}
Output
The time is Tue Mar 21 15:26:41.341 1995