Skip to content

Instantly share code, notes, and snippets.

@christiankakesa
Created November 28, 2010 19:17
Show Gist options
  • Save christiankakesa/719215 to your computer and use it in GitHub Desktop.
Save christiankakesa/719215 to your computer and use it in GitHub Desktop.
gettimeofday
//...
#if defined(WINXX)
#include <sys/timeb.h>
typedef struct timeval {
__time64_t tv_sec;
long tv_usec;
} timeval;
#else
#include <sys/time.h>
#endif //defined(WINXX)
//...
class Time
{
public:
static unsigned long int GetTimeInMilli()
{
unsigned long int res = 0;
struct timeval tim;
#if defined(WINXX)
struct _timeb timebuffer;
_ftime64_s(&timebuffer);
tim.tv_sec = timebuffer.time;
tim.tv_usec = timebuffer.millitm * 1000;
#else //Assuming linux
gettimeofday(&tim, NULL);
#endif //defined(WINXX)
res = tim.tv_sec * 1000 + static_cast<unsigned long int>(tim.tv_usec / 1000);
return res;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment