标准CC++获取当前时间(毫秒级)

时间:2021-07-25 00:39:37

直接上代码了

#include<sys/timeb.h>
void getSystemTime(string& stime)
{

	timeb t;
        ftime(&t);
	char tmp[16];
	strftime(tmp,sizeof(tmp),"%Y%m%d%H%M%S",localtime(&t.time));//Year Month Day Hour Minute Second
	char tm[20];
	sprintf(tm, "%s%d",tmp,t.millitm);
	stime=tm;

}
void main()
{
           string nowtime;//存储获取的系统的时间    
	   getSystemTime(nowtime);
}