Linux??timeval????????????,?????????????????:
-
???time_t:timeval?????tv_sec?????????time_t??,???1970?1?1???????
-
??????:????ctime()???timeval???????????????
-
???tm???:????gmtime()?localtime()???timeval??????tm???,???????????
-
?????:???timeval?????tv_sec????1000???tv_usec????1000,??????
??????:
#include#include int main() { struct timeval tv; gettimeofday(&tv, NULL); time_t sec = tv.tv_sec; printf("tv_sec: %ld\n", sec); char *str = ctime(&tv.tv_sec); printf("ctime: %s", str); struct tm *tm = gmtime(&tv.tv_sec); printf("gmtime: %d-d-d d:d:d\n", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); long long ms = (long long)tv.tv_sec * 1000 + tv.tv_usec / 1000; printf("milliseconds: %lld\n", ms); return 0; }
??????????timeval???????????,????????????????