The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 11-19-2007
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,938
You can use the gettimeofday() and the timeval structure to achieve what you want.

#include <stdio.h>
#include <time.h>
#include <sys/time.h>

int
main(void)
{
char buf[30];
struct timeval tv;
time_t ct;
int ms;

gettimeofday(&tv, NULL);
ct = tv.tv_sec;
strftime(buf, 30, "%m/%d/%y %T.", localtime(&ct));
ms = (tv.tv_usec % 1000000) / 1000;

printf("Timestamp: %s%d\n", buf, ms);
}