如何得到2010年8月9日与2003年1月31日之间的时间差,并转为成天数?

解决方案 »

  1.   

    可以用CTime,CTime t1(2010,8,9,0,0,0),CTime t2(2003,1,31,0,0,0);
    (t1.GetTime()-t2.GetTime)/3600/24 就是时间差天数了timespan好象也可以。
      

  2.   

    CTimeSpan ts=CTime(2010,8,9,0,0,0) - CTime(2003,1,31,0,0,0);
    int nDayts=static_cast<int>((ts.GetTotalSeconds()+86399)/86400);
      

  3.   

    CTimeSpan::GetDaysSee Also
    CTimespan Overview | Class Members | Hierarchy Chart
    Returns a value that represents the number of complete days in this CTimeSpan.LONGLONG GetDays( ) const throw( );
    Return Value
    Returns the number of complete 24-hour days in the time span. This value may be negative if the time span is negative.Res
    Note that Daylight Savings Time can cause GetDays to return a potentially surprising result. For example, when DST is in effect, GetDays reports the number of days between April 1 and May 1 as 29, not 30, because one day in April is shortened by an hour and therefore does not count as a complete day.Example
    // example for CTimeSpan::GetDays
    CTimeSpan ts( 3, 1, 5, 12 ); // 3 days, 1 hour, 5 min, and 12 sec
    ATLASSERT( ts.GetDays() == 3 );
      

  4.   

    CTime tm(....);//
    time_t time=tm.GetTime(); //CTime--->time_t
    CTimeSpan span(time);
    span.GetDays();