CString time1 ="2007-06-13 10:10:10";
CString time2 ="2007-06-13 20:10:10";
CTime tNow = CTime::GetCurrentTime ();
CString szMsgBuffer = tNow.Format ("%Y-%m-%d %H:%M:%S");
if(szMsgBuffer > time1  && time2  < szMsgBuffer)
{
AfxMessageBox("ye"); }
else{AfxMessageBox("no");}

解决方案 »

  1.   

    1. Covert CTime and CString to SYSTEMTIME.
    2. Covert SYSTEMTIME to FILETIME.
    3. Compare times using FILETIME.//CString to SYSTEMTIME
    CString str = "2007-06-13 10:10:10";     
    COleVariant vt(str);   
    vt.ChangeType(VT_DATE);   
    COleDateTime odt = vt;   
    SYSTEMTIME st;
    VariantTimeToSystemTime(odt, &st);   
    //CTime to SYSTEMTIME
    CTime  time(CTime::GetCurrentTime());  
    SYSTEMTIME st;  
    time.GetAsSystemTime(st); 
    //SYSTEMTIME to FILETIME
    SystemTimeToFileTime 
      

  2.   

    直接比較time1,time2就可以。直接按照字符串比較,字符串比較就是按照字符的ascii碼比較的。所以也可以這麽比較日期。畢竟
    CString time1 ="2007-06-13 10:10:10";
    CString time2 ="2007-06-13 20:10:10";
    time2字符串肯定比time1字符串大。
      

  3.   

    直接比较是可以的,应该是
    CString szMsgBuffer = tNow.Format ("%Y-%m-%d %H:%M:%S");
    得到的字符串和time1类型不一样
      

  4.   

    //if(tiem2.Collate(tiem1)>=0)
    int a=strcmp(tiem1,tiem2);
    if(a>0)
    {
    AfxMessageBox("ye"); }
    else{

    AfxMessageBox("no");}
    上面的两种字符串比较是否安全呢!!
      

  5.   

    LONG CompareFileTime( 
      const FILETIME* lpFileTime1, 
      const FILETIME* lpFileTime2 
    );
      

  6.   

    楼主你这样做了 CTime tNow = CTime::GetCurrentTime ();
     就用Ctime 直接比较好了,何必用CString来比较