当前位置:网站首页>Ustime wrote a bug

Ustime wrote a bug

2022-07-01 12:41:00 Tao song remains the same

lately , Wrote a ustime function , Accidentally made a bug, Checked the , Repair the .

then , I think , This function should be very common , So I searched the open source code , Sure enough , Come and see what others write :

/* Return the UNIX time in microseconds */
long long ustime(void) {
    struct timeval tv;
    long long ust;
 
    gettimeofday(&tv, NULL);
    ust = ((long long)tv.tv_sec)*1000000;
    ust += tv.tv_usec;
    return ust;
}
 
/* Return the UNIX time in milliseconds */
mstime_t mstime(void) {
    return ustime()/1000;
}

After testing , OK, It's much clearer .

原网站

版权声明
本文为[Tao song remains the same]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/182/202207011233038077.html