intmilliseconds=ts.tv_nsec/1000000;// 将纳秒转换为毫秒 chartime_string[30]; strftime(time_string,sizeof(time_string),"%Y-%m-%d %H:%M:%S",local_time); printf("当前时间: %s.%03d\n",time_string,milliseconds); return0; } 该代码使用clock_gettime()函数获取当前时间戳,然后利用localtime()函...
intmain(){ // 获取当前系统时间戳(秒) time_tcurrent_time; time(¤t_time); // 转换为本地时间结构体 structtm*local_time=localtime(¤t_time); // 格式化输出 charformatted_time[30]; // 获取当前毫秒数 structtimespec ts; clock_gettime(CLOCK_REALTIME,&ts); longmilliseconds=ts.tv_...