응용 프로그램 개발/C++, MFC, Windows
[MFC] CString 과 CTime 간 변환
닉ㄴ네
2020. 12. 10. 18:51
728x90
반응형
1. CTime을 CString으로 변환
// CTime을 CString으로 변환
CString strDateTime;
CTime tiTime(2020, 12, 03, 16, 02, 25);
strDateTime = tiTime.Format(_T("%Y-%m-%d %H:%M:%S"));
//strDateTime = "2020-12-03 16:02:25";
//현재시간을 년월일시분초 로 표현
//CTime::GetCurrentTime() 은 현재시간
CString strTime = CTime::GetCurrentTime().Format(L"%Y%m%d%H%M%S");
2. CString을 CTime으로 변환
void GetCStringtoCTime(CString strTime, CTime& cTime)
{
//strDateTime = "2020-12-03 16:02:25";
CStringA strYear, strMonth, strDay, strHour, strMin, strSec;
strYear = strTime.Left(4);
strMonth = strTime.Mid(5, 2);
strDay = strTime.Mid(8, 2);
int nFind = strTime.Find(L":");
strHour = strTime.Mid(nFind -2, 2);
strMin = strTime.Mid(nFind + 1, 2);
strSec = strTime.Mid(nFind + 4, 2);
cTime = CTime(atoi(strYear), atoi(strMonth), atoi(strDay), atoi(strHour), atoi(strMin), atoi(strSec));
}
728x90
반응형