#define _CRT_SECURE_NO_WARNINGS
#include <stdint.h>
#include <stdio.h>
#ifdef _WIN32
#include <time.h>
#include<windows.h>
#else
#include <sys/time.h>
#include <unistd.h>
#endif
uint64_t GetCurrentTimerMS()
{
uint64_t nTimer = 0;
#ifdef _WIN32
SYSTEMTIME currentTime;
GetLocalTime(¤tTime);
tm temptm = { currentTime.wSecond,
currentTime.wMinute,
currentTime.wHour,
currentTime.wDay,
currentTime.wMonth - 1,
currentTime.wYear - 1900
};
nTimer = mktime(&temptm) * 1000 + currentTime.wMilliseconds;
#else
struct timeval tv;
gettimeofday(&tv, NULL);
// printf("second:%ld\n",tv.tv_sec); //秒
nTimer = tv.tv_sec * 1000 + tv.tv_usec / 1000;
#endif
return nTimer;
}
int main()
{
char szTimer[64];
uint64_t nTimer = -1;
nTimer = GetCurrentTimerMS(); //不带参数
printf("millisecond:\t%llu\n\n", nTimer); //毫秒
return 0;
}