MFC datetimepicker 如何赋值
voidCClientDlg::SetDateTimePicker(){CStringstrItem1=m_lstDtf.GetItemText(0,0);CString...
void CClientDlg::SetDateTimePicker()
{
CString strItem1 = m_lstDtf.GetItemText(0,0);
CString strDate = strItem1.Left(10);
CString strTime = strItem1.Right(8);
int year,month,day,hour,minute,second;
int pos1 = 0,pos2 = 0,pos3 = 0,pos4 = 0;
pos2 = strDate.Find('-',pos1);
year = strtol(strDate.Mid(pos1,pos2),NULL,10);
pos1 = pos2 + 1;
pos2 = strDate.Find('-',pos1);
month = strtol(strDate.Mid(pos1,pos2),NULL,10);
pos1 = pos2 + 1;
day = strtol(strDate.Mid(pos1),NULL,10);
pos4 = strTime.Find(':',pos3);
hour = strtol(strTime.Mid(pos3,pos4),NULL,10);
pos3 = pos4 + 1;
pos4 = strTime.Find(":",pos3);
minute = strtol(strTime.Mid(pos3,pos4),NULL,10);
pos3 = pos4 + 1;
second = strtol(strTime.Mid(pos3),NULL,10);
CTime time(year,month,day,hour,minute,second);
m_dtYMD.SetTime(&time);
m_dtHMS.SetTime(&time);
}
代码可以运行成功。我在程序里选择有日期时间的文件夹不会报错,但是选择没有日期时间的文件夹会报错。请各位大神帮我看看,先谢谢了 展开
{
CString strItem1 = m_lstDtf.GetItemText(0,0);
CString strDate = strItem1.Left(10);
CString strTime = strItem1.Right(8);
int year,month,day,hour,minute,second;
int pos1 = 0,pos2 = 0,pos3 = 0,pos4 = 0;
pos2 = strDate.Find('-',pos1);
year = strtol(strDate.Mid(pos1,pos2),NULL,10);
pos1 = pos2 + 1;
pos2 = strDate.Find('-',pos1);
month = strtol(strDate.Mid(pos1,pos2),NULL,10);
pos1 = pos2 + 1;
day = strtol(strDate.Mid(pos1),NULL,10);
pos4 = strTime.Find(':',pos3);
hour = strtol(strTime.Mid(pos3,pos4),NULL,10);
pos3 = pos4 + 1;
pos4 = strTime.Find(":",pos3);
minute = strtol(strTime.Mid(pos3,pos4),NULL,10);
pos3 = pos4 + 1;
second = strtol(strTime.Mid(pos3),NULL,10);
CTime time(year,month,day,hour,minute,second);
m_dtYMD.SetTime(&time);
m_dtHMS.SetTime(&time);
}
代码可以运行成功。我在程序里选择有日期时间的文件夹不会报错,但是选择没有日期时间的文件夹会报错。请各位大神帮我看看,先谢谢了 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询