linux 获取当前时间,精确到毫秒

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/we1583004we/article/details/80612544

linux下获取当前系统时间,代码如下:

void sysTime(void)
{
    struct timeval tv;
    struct timezone tz;   
    struct tm *t;
     
    gettimeofday(&tv, &tz);
    t = localtime(&tv.tv_sec);
    printf("time_now:%d-%d-%d %d:%d:%d.%ld\n", 1900+t->tm_year, 1+t->tm_mon, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec);
}

猜你喜欢

转载自blog.csdn.net/we1583004we/article/details/80612544