毫秒级时间戳(两种方法)
#include <stdio.h>
#include <windows.h>
#include<time.h>
/*
time_t GetCurrentTimeStampMS1(){
SYSTEMTIME currentTime = {0};
GetLocalTime(¤tTime);
struct tm currTm = {
currentTime.wSecond,
currentTime.wMinute,
currentTime.wHour,
currentTime.wDay,
currentTime.wMonth - 1,
currentTime.wYear - 1900
};
time_t nNow = mktime(&currTm) * 1000 + currentTime.wMilliseconds;
return nNow;
}
*/
int GetCurrentTimeStampMS2(){
struct timeb rawtime;
ftime(&rawtime);
return rawtime.time*1000 + rawtime.millitm;
}
int main( void )
{
//time_t nowTime = NULL;
int a = NULL;
while(1){
//nowTime=GetCurrentTimeStampMS1();
a=GetCurrentTimeStampMS2();
//printf("1:%ld\n\n,2:%ld\n",nowTime,a);
printf("%ld\n",a);
Sleep(1000);
//system("cls"); 清屏
}
return 0;
}