用OpenCV做多摄像头校准时间,在图像上显示时间信息,需求要将COleDateTime类型数据转换成char *数据
具体代码如下:
1: COleDateTime m_checkDate;2: COleDateTime timeCur;3: timeCur = COleDateTime::GetCurrentTime();4: COleDateTime timeStart(timeCur.GetYear(), timeCur.GetMonth(), timeCur.GetDay(), timeCur.GetHour(), timeCur.GetMinute(), timeCur.GetSecond());5: m_checkDate = timeStart;6:7: CString str_tempTime = m_checkDate.Format(_T("%Y-%m-%d %H:%M:%S"));
8:9: int n = str_tempTime.GetLength();
10: //获取宽字节字符的大小,大小是按字节计算的
11: int len = WideCharToMultiByte(CP_ACP, 0, str_tempTime, str_tempTime.GetLength(), NULL, 0, NULL, NULL);
12: //为多字节字符数组申请空间,数组大小为按字节计算的宽字节字节大小
13: char * pFileName = new char[len + 1]; //以字节为单位14: //宽字节编码转换成多字节编码
15: WideCharToMultiByte(CP_ACP, 0, str_tempTime, str_tempTime.GetLength(), pFileName, len, NULL, NULL);16: pFileName[len] = ' '; //多字节字符以' '结束