Windows下使用timeval以及gettimeofday() 毫秒

参考博客:https://blog.csdn.net/CUSTESC/article/details/104968050

struct timeval
{
    __int64 tv_sec;
    __int64 tv_usec;
};


void gettimeofday(struct timeval* tv) {

    auto time_now = std::chrono::system_clock::now();
    std::chrono::system_clock::time_point tp = std::chrono::system_clock::now();
    auto duration_in_s = std::chrono::duration_cast<std::chrono::seconds>(time_now.time_since_epoch()).count();
    auto duration_in_us = std::chrono::duration_cast<std::chrono::microseconds>(time_now.time_since_epoch()).count();

    tv->tv_sec = duration_in_s;
    tv->tv_usec = duration_in_us;
}
文章目录