COleDateTime tempTime;
COleDateTimeSpan tempSpan(7, 0, 0, 0);
COleDateTime timeBegin;timeBegin.ParseDateTime("2010-07-10");
tempTime = timeBegin + tempSpan;我想得到的是tempTime这个时间,不使用MFC..

解决方案 »

  1.   

    你讲清楚你要的是什么,COleDateTime 是个类,功能有很多
      

  2.   

    以前由于项目需求,写过这样一个函数:#include <afx.h>
    #include <afxdisp.h>/********************************************************************
    *  Function: SubTime      
    *  Description: 计算两个日期天数之差   
    *  Input: CString strStart [开始时间,如2010-05-28] 
    * CString strEnd [结束时间,如2010-06-28] 
    *  Output: None
    *  Return: CString [天数差]     
    *  Others:      None   
    *********************************************************************/
    CString SubTime(CString strStart,CString strEnd)
    {
    CString  strDates = "0";
    if(strStart.IsEmpty() || strEnd.IsEmpty())
    {
    return strDates;
    }

    COleVariant  vtime1(strStart);
    COleVariant  vtime2(strEnd);
    vtime1.ChangeType(VT_DATE);
    vtime2.ChangeType(VT_DATE);

    COleDateTime timeS = vtime1;
    COleDateTime timeE = vtime2;
    SYSTEMTIME  stS,stE;
    VariantTimeToSystemTime(timeS,&stS);
    VariantTimeToSystemTime(timeE,&stE);

    CTime tmS(stS);
    CTime tmE(stE);
    CTimeSpan span = tmE-tmS;
    strDates.Format("%d",span.GetDays());
    return strDates;
    }
    /********************************************************************
    *  Function: AddTime      
    *  Description: 计算某日期,若干天后的日期   
    *  Input: CString strStart [开始时间,如2010-05-28] 
    * int     nDays [天数] 
    *  Output: None
    *  Return: CString [nDays天后的日期]     
    *  Others:      None   
    *********************************************************************/
    CString AddDates(CString strDate,int nDays)
    {
    CString strTemp = "";
    if(strDate.IsEmpty())
    {
    return strTemp;
    }

    COleVariant  vtime(strDate);
    vtime.ChangeType(VT_DATE);

    COleDateTime time = vtime;
    SYSTEMTIME  st;
    VariantTimeToSystemTime(time,&st);

    CTime tm1(st);
    CTime tm2(tm1.GetYear(),tm1.GetMonth(),tm1.GetDay() + nDays,0,0,0);

    strTemp.Format("%04d-%02d-%02d",tm2.GetYear(),tm2.GetMonth(),tm2.GetDay());
    return strTemp;
    }void main()
    {
        MessageBox(NULL,SubTime("2010-02-01","2010-03-01"),NULL,NULL);
        MessageBox(NULL,AddDates("2010-02-25",10),NULL,NULL);
    }
      

  3.   

    我要的就是不使用COleDateTime 实现相似功能了