如果你知道CString 的年月日的顺序
干脆用CTime的构造函数酸了

解决方案 »

  1.   

    在VB中CDate可以将STRING转换成DATE,但VC中不知用什么函数?
      

  2.   

    把它CString对向塞到CTime构造函数里,不行就只能自己把他拆开来了。
    不好意思,没看过帮助有没有。
      

  3.   

    掩码框,看MSDN有关CTime的吧,
      

  4.   

    CTime ltime;
    CString str;str.Formate("%s",ltime.Format("%Y-%m-%d %H:%M:%S"))
      

  5.   

    CTime timenow;       //现在时间
    CString temptime;    //以H:M:S形式表示的现在时间
    timenow=CTime::GetCurrentTime();
    temptime=timenow.Format("%H:%M:%S");
      

  6.   

    COleDateTime::ParseDateTime
    BOOL ParseDateTime( LPCTSTR lpszDate, DWORD dwFlags = 0, LCID lcid = LANG_USER_DEFAULT );
    throw( CMemoryException );
    throw( COleException );Return ValueNonzero if the string was successfully converted to a date/time value, otherwise 0.ParameterslpszDateA pointer to the null-terminated string which is to be parsed. For details, see Res.dwFlagsIndicates flags for locale settings and parsing. One or more of the following flags: LOCALE_NOUSEROVERRIDE   Use the system default locale settings, rather than custom user settings.
    VAR_TIMEVALUEONLY   Ignore the date portion during parsing.
    VAR_DATEVALUEONLY   Ignore the time portion during parsing. 
    lcidIndicates locale ID to use for the conversion.ResCall this member function to parse a string to read a date/time value. If the string was successfully converted to a date/time value, the value of this COleDateTime object is set to that value and its status to valid.Note   Year values must lie between 100 and 9999, inclusively.The lpszDate parameter can take a variety of formats. For example, the following strings contain acceptable date/time formats:"25 January 1996"
    "8:30:00"
    "20:30:00"
    "January 25, 1996 8:30:00"
    "8:30:00 Jan. 25, 1996"
    "1/25/1996 8:30:00"  // always specify the full year,
                         // even in a 'short date' formatNote that the locale ID will also affect whether the string format is acceptable for conversion to a date/time value.In the case of VAR_DATEVALUEONLY, the time value is set to time 0, or midnight. In the case of VAR_TIMEVALUEONLY, the date value is set to date 0, meaning 30 December 1899.If the string could not be converted to a date/time value or if there was a numerical overflow, the status of this COleDateTime object is invalid.If the string conversion failed due to memory allocation errors, this function throws a CMemoryException. In any other error state, this function throws a COleException.For a listing of locale ID values, see the sectionSupporting Multiple National Languages in the Win32 SDK OLE Programmer’s Reference.For more information about the bounds and implementation for COleDateTime values, see the articleDate and Time: Automation Support in Visual C++ Programmer’s Guide.
      

  7.   

    以上各位老兄基本上都是将CTime转化成CStrig.但怎样将CString 转换成CTime?
    如有一CString str ="01 Nov 1999" 怎样将它转换成CTime?
      

  8.   

    CTime t1( 2001, 12, 31, 23, 59, 0 );  //2001/12/31 23:59:00
    time_t WantTime = t1.GetTime();WantTime为结果
      

  9.   

    将字符串成 CTime 比较麻烦点,但并不是不可以实现,以下是我写的一个简单例子,只是要告诉你实现的原理,你自己可以细化。CTime * pTime;
    char buff[5];
    CString pStrTime;
    pStrTime="1999-01-23";
    int pYear,pMonth,pDay;
    strncpy(buff,(LPCSTR)pStrTime,4);
    pYear=atoi(buff);
    strncpy(buff,(LPCSTR)pStrTime+5,2);  
    pMonth=atoi(buff);   //如果你字符串日期 中的 月份是英文,就不能用这个,用条件来判断并转换成对应数字
    strncpy(buff,(LPCSTR)pStrTime+8,2);  
    pDay=atoi(buff);pTime=new CTime(pYear,pMonth,pDay,0,0,0);如果还是不明白,写邮件告诉我,希望我能帮助你,我的邮箱:[email protected]