在 Windows 上使用 Win32 API
SYSTEMTIME 结构会给你毫秒。然后,您应该使用时间函数来获取时间。像这样:
#include <windows.h>
int main()
{
SYSTEMTIME stime;
//structure to store system time (in usual time format)
FILETIME ltime;
//structure to store local time (local time in 64 bits)
FILETIME ftTimeStamp;
char TimeStamp[256];//to store TimeStamp information
GetSystemTimeAsFileTime(&ftTimeStamp); //Gets the current system time
FileTimeToLocalFileTime (&ftTimeStamp,<ime);//convert in local time and store in ltime
FileTimeToSystemTime(<ime,&stime);//convert in system time and store in stime
sprintf(TimeStamp, "%d:%d:%d:%d, %d.%d.%d",stime.wHour,stime.wMinute,stime.wSecond,
stime.wMilliseconds, stime.wDay,stime.wMonth,stime.wYear);
printf(TimeStamp);
return 0;
}