请教高手  如何比较两个日期时间的先后?
我已经取得了年 月 日 时 分 秒

解决方案 »

  1.   

    CTime类有比较时间先后的操作符,你创建CTime类对象进行比较就行了。
      

  2.   

    time_t: 直接比较,大的靠后。
    CTime: GetTime()比较。
    COleDateTime: 比较m_dt,大的靠后。
    字符串:格式相同可以用strcmp()
      

  3.   

    假如有两个CTime对象t1,t2;
    time_t tt1,tt2;
    tt1 = t1.GetTime();
    tt2 = t2.GetTime();
    比较tt1和tt2就可以了,time_t实际是long类型。
    是按秒算的。
      

  4.   

    if ( ( tt1 - tt2 ) > 0 )
        t1 more than t2;
    else
        t2 more than t1;
    you can test
      

  5.   

    可以用CTime类,类中有重载了的<,>,==操作符
      

  6.   

    CTime time1,time2;
    ...
    if(time1>time2){
       ...
    }
      

  7.   

    哎呀,楼主和不看看MSDN?Example// example for CTime::operator  +, -
    CTime t1( 1999, 3, 19, 22, 15, 0 ); // 10:15PM March 19, 1999
    CTime t2( 1999, 3, 20, 22, 15, 0 ); // 10:15PM March 20, 1999
    CTimeSpan ts = t2 - t1;  // Subtract 2 CTimes
    ASSERT( ts.GetTotalSeconds() == 86400L );
    ASSERT( ( t1 + ts ) == t2 );  // Add a CTimeSpan to a CTime.
    ASSERT( ( t2 - ts ) == t1 );  // Subtract a CTimeSpan from a Ctime.CTime t1( 1999, 3, 19, 22, 15, 0 ); 这样子的定义,你可以不要年等。。
    只要时间正确。
    =
    +  - 
    还有
    BOOL operator ==( CTime time ) const;BOOL operator !=( CTime time ) const;BOOL operator <( CTime time ) const;BOOL operator >( CTime time ) const;BOOL operator <=( CTime time ) const;BOOL operator >=( CTime time ) const;都是可以用来计算的。
      

  8.   

    GetTotalSeconds() 是个
    CTimeSpan Class Members可以用它的
    GetTotalHours Returns the total number of complete hours in this CTimeSpan. GetTotalMinutes Returns the total number of complete minutes in this CTimeSpan. GetTotalSeconds Returns the total number of complete seconds in this CTimeSpan. 
    这三个函数来统计换算你的时间差---------ts