C++_CTime/COleDateTime時間

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:code

構造函數:orm

COleDateTime(int nYear, int nMonth, int nDay,int nHour, int nMin, int nSec) throw();

獲取當前時間:class

COleDateTime curTime = COleDateTime::GetCurrentTime();
CString strCurTime = curTime.Format(_T("%Y-%m-%d %H:%M:%S"));

比較時間:sed

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("結束時間不能比開始時間早!"));
	}
}
相關文章
相關標籤/搜索