I want to print time in the format hh:mm:ss:ms(milliseconds). I could print in the form of hh:mm:ss. What can be the way to print remaining milliseconds?
#include<sys/timeb.h>
#include<time.h>
int main(void) {
struct timeb tp;
ftime(&tp);
char timeString[80];
strftime(timeString, sizeof(timeString), "%H:%M:%S", localtime(&tp.time));
printf("%s:%d", timeString, tp.millitm);
return 0;
}
If you're working with the MSDN library, you could try
GetSystemTimeAsFileTime( pointerToSetToTime );
Which sets a pointer argument to the current system time in 100-nanosecond intervals.
This is what I use in linux ...
struct timeval tv;
gettimeofday(&tv,0);
time_t long_time;
struct tm *newtime;
time(&long_time);
newtime = localtime(&long_time);
char result[100] = {0};
sprintf(result, "%02d:%02d:%02d.%03ld", newtime->tm_hour,newtime->tm_min,newtime->tm_sec, (long)tv.tv_usec / 1000);
return result;
I have no experience working in windows .. try to find similar calls ..