#include "sys/timeb.h"
void printlog(TCHAR* patch,TCHAR* msg)//打印函数
{
CFileStatus status;
CString p(patch);
CFile::GetStatus( p, status );
if(status.m_size >= 4000000)//文件大于4m删除
{
::DeleteFile(p);
}
FILE *fp;
fp=_tfopen(patch,_T("ab+"));//打开文件
if (!fp)
{
return;
}
CTime Tm=CTime::GetCurrentTime(); //计算时间
int nYear,nMonth,nDay,nHour,nMinute,nSecond,nMinSecond;
nYear=Tm.GetYear();
nMonth=Tm.GetMonth();
nDay=Tm.GetDay();
nHour=Tm.GetHour();
nMinute=Tm.GetMinute();
nSecond=Tm.GetSecond();
CString mSecond;
struct _timeb timebuffer;
_ftime(&timebuffer);
mSecond.Format( _T("%d "),timebuffer.millitm);
nMinSecond=_ttoi(mSecond);
TCHAR g_szDateTime[5000]={0};
_stprintf(g_szDateTime, _T("%04d-%02d-%02d %02d:%02d:%02d.%3d: %s
"),
nYear,nMonth,nDay,nHour,nMinute,nSecond,nMinSecond,msg);
fwrite(g_szDateTime, sizeof(TCHAR), _tcslen(g_szDateTime), fp);
fclose(fp);
}
运行结果:2019-03-06 18:47:00.193: 进入写包REG