获取系统时间

#include <time.h>
#include <sys/timeb.h>

CTime t = CTime::GetCurrentTime();
int nYear = t.GetYear() - 2000;
int nMonth = t.GetMonth();
int nDay = t.GetDay();
int nTime = t.GetHour();
int nMin = t.GetMinute();
int nSec = t.GetSecond();

CString mSecond;
struct _timeb timebuffer;
_ftime(&timebuffer);
mSecond.Format(_T("%d"), timebuffer.millitm);
int nMinSec = _ttoi(mSecond);

// srand((int)time(0));
// srand(1);
//
// int iRand = rand();
// CString sRand;
// sRand.Format(_T("%2d"), iRand);

CString str;
str.Format(_T("%2d%2d%2d%2d%2d%2d%2d"), nYear,nMonth, nDay,nTime,nMin,nSec,nMinSec);
str.Replace(_T(' '), _T('0'));

 

精确到毫秒

 

posted @ 2016-01-06 15:40  xzh1993  阅读(187)  评论(0编辑  收藏  举报