例如:
CString str1="2002-11-22";
现在想把str1转换成时间类型,能够使用CTime成员函数进行计算,请问如何实现?谢谢。

解决方案 »

  1.   

    好象没有现成的函数,自己写个函数吧^-^
    CTime strTotime(CString str)
    {
    int nStart = 0;
    nEnd = 0;
    bWork = TRUE;
    int nYear = 0;
    int nMonth = 0;
    int nDay = 0;
    if(bWork)
    {
       nEnd = UserInfo.Find('-',nStart );
       if(nEnd == -1)
       {
          nDay = ....
          break;
       }
       nLength = nEnd - nStart - 1;
       CString strYear = str.Mid(nStart+1,nLength); 
       int nYear = atoi(strYear);
       nStart = nEnd + 1;
       CTime time(nYear,nMonth,nDay,0,0,0);
       return time;
    }
      

  2.   

    CString year=str1.Mid(0,4);
    CString month=str1.Mid(5,2);
    CString day=str1.Mid(8,2);
    CTime time(atof(year),atoi(month),atoi(day),0,0,0);试试看,应该能行