Get millisecond part of time

后端 未结 8 1972
再見小時候
再見小時候 2020-12-18 22:07

I need to get milliseconds from the timer

    // get timer part
    time_t timer = time(NULL);
    struct tm now = *localtime( &timer );
    char timesta         


        
8条回答
  •  Happy的楠姐
    2020-12-18 22:12

    On Windows using Win32 API SYSTEMTIME structure will give you milliseconds. Then, you should use Time Functions to get time. Like this:

    #include 
    
    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;
    } 
    

提交回复
热议问题