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);
}

posted @ 2020-12-21 09:30  wioponsen  阅读(2613)  评论(0编辑  收藏  举报