Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time stamping

Status
Not open for further replies.

AndyHollywood

Programmer
Oct 7, 2001
30
GB
I am trying to add a time stamp to a stream that is outputting to text file:

fprintf(pDEBUG, "DEBUGFILTER\tCalled %d times \n",++Called);

how would i go about getting a very very accurae stamp into this stream?

cheers in advance

Andy
 
This will go down to the milli seconds.

You'll need:

#include <time.h> // needed for time and delta time
#include <sys/timeb.h>



struct _timeb timebuffer;
char *timeline;
_ftime( &timebuffer );
char cTime[25];

timeline = ctime( & ( timebuffer.time ) );

sprintf(cTime,&quot;%.8s.%0.3u\n&quot;,&timeline[11],timebuffer.millitm);

AfxMessageBox(cTime);
 
This code gives a basic time stamp

#include <ctime>

struct tm *ptr;
time_t lt;

lt = time(NULL);
ptr = localtime(&lt);

cout << asctime(ptr) << endl;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top