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

double
now( void )
{ 
  struct timeval tv;
  int timeout = 10;
  while ( gettimeofday( &tv, NULL ) == -1 && timeout > 0 ) timeout--;
  return tv.tv_sec + tv.tv_usec * 1E-6;
}

int
main( void )
{
  char buffer[128];
  char frac[16];
  double integer, fraction = modf( now(), &integer );
  time_t start_time = (time_t) ((long) integer);
  struct tm* start_tm = localtime(&start_time);

  strftime( buffer, 128, "%H:%M:%S", start_tm );
  sprintf( frac, "%#.3f", fraction );
  printf( "%s%s\n", buffer, frac+1 );
  return 0;
}
