linux 获取当前时间,精确到毫秒
程序员文章站
2024-01-24 09:22:10
...
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);
}