CTime:获取时间
CString strTime;
CTime timeCurr = CTime::GetCurrentTime();
strTime.Format(_T("%d%d%d%d%d%d"),timeCurr.GetYear(),timeCurr.GetMonth(),timeCurr.GetDay(),timeCurr.GetHour(),timeCurr.GetMinute(),timeCurr.GetSecond());
COleDateTime:
构造函数:
COleDateTime(int nYear, int nMonth, int nDay,int nHour, int nMin, int nSec) throw();
获取当前时间:
COleDateTime curTime = COleDateTime::GetCurrentTime();
CString strCurTime = curTime.Format(_T("%Y-%m-%d %H:%M:%S"));
比较时间:
CString strStart = _T("1999-10-03 10:12:45");
CString strEnd = _T("2018-01-03 10:12:45");
COleDateTime timeStart;
COleDateTime timeEnd;
if (timeStart.ParseDateTime(strStart) && timeEnd.ParseDateTime(strEnd))
{
COleDateTimeSpan timeElapsed = timeEnd - timeStart;
if (timeElapsed.GetTotalSeconds() < -1e-6)
{
HHTalkBox(_T("结束时间不能比开始时间早!"));
}
}