C语言获取日期和时间以及毫秒

#include <time.h>

void get_time_str(char* name)
{
	time_t timep;
	struct tm *p;
	time(&timep);
	p = gmtime(&timep);
	clock_t t = clock();
	int ms = t * 1000/ CLOCKS_PER_SEC % 1000;
	sprintf(name, "%d-%d-%d_%02d:%02d:%02d-%03d", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, 8 + p->tm_hour, p->tm_min, p->tm_sec, ms);
}

原文地址:https://www.cnblogs.com/wioponsen/p/14166431.html