CTime转换为CString
CTime time1 = CTime::GetCurrentTime();
CString str1 = time1.Format("%Y-%m-%d %H:%M:%S");
//取得CTime中的日期
CString cstrDate = tmScan.Format("%Y-%m-%d");
//取得CTime中的时间
CString cstrTime = tmScan.Format("%H:%M-%S");
CString转换为CTime
CString timestr = "2011-7-21 12:16:28";
int nYear, nMonth, nDate, nHour, nMin, nSec;
sscanf(timestr, "%d-%d-%d %d:%d:%d", &nYear, &nMonth, &nDate, &nHour, &nMin, &nSec);
CTime t(nYear, nMonth, nDate, nHour, nMin, nSec);
CString timestr = "2011年7月21日";
int a,b,c;
sscanf(timestr.GetBuffer(timestr.GetLength()),"%d年%d月%d日",&a,&b,&c);
CTime time(a,b,c,0,0,0);
CTime m_StartTime1 = CTime::GetCurrentTime();
CString csStartTime = m_StartTime1.Format( "%Y%m%d%H%M%S" );
使用sprintf及sscanf函数进行CString与CTime之间的转换比较方便。