2

I tried to use gettimeofday function, but it calculates the time passed since the Epoch, and that's not what I need.

Can someone help?

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
kakush
  • 3,334
  • 14
  • 47
  • 68
  • What do you need really? – Chris Zheng Dec 08 '11 at 15:38
  • How is that not what you want ? (you can easily convert the seconds/microseconds in the struct timeval to e.g. a long long of miliseconds) – nos Dec 08 '11 at 15:39
  • Also, you can refer this already answered [question](http://stackoverflow.com/questions/5362577/c-gettimeofday-for-computing-time) in stackoverflow – Chris Zheng Dec 08 '11 at 15:46

1 Answers1

7

I think this should work for you.

#include <time.h>
#include <stdlib.h>
#include <stdio.h>

int main(void)
{
  char buffer[30];
  struct timeval tv;

  time_t curtime;



  gettimeofday(&tv, NULL);
  curtime=tv.tv_sec;

  strftime(buffer,30,"%m-%d-%Y  %T.",localtime(&curtime));
  printf("%s%ld\n",buffer,tv.tv_usec);

  return 0;
}
Imposter
  • 2,666
  • 1
  • 21
  • 31