How to get the time elapsed in C in milliseconds? (Windows)

后端 未结 6 1777
栀梦
栀梦 2021-02-14 09:39

I\'ve searched in the Web but I\'ve only found a way for do it, but in this way it returns in seconds instead of milliseconds.

My code is:

#include 

        
6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-14 10:15

    This code piece works. This is based on the answer from Angus Comber:

    #include 
    
    uint64_t system_current_time_millis()
    {
    #if defined(_WIN32) || defined(_WIN64)
        struct _timeb timebuffer;
        _ftime(&timebuffer);
        return (uint64_t)(((timebuffer.time * 1000) + timebuffer.millitm));
    #else
        struct timeb timebuffer;
        ftime(&timebuffer);
        return (uint64_t)(((timebuffer.time * 1000) + timebuffer.millitm));
    #endif
    }
    

提交回复
热议问题