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);
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 );
(t1.GetTime()-t2.GetTime)/3600/24 就是时间差天数了timespan好象也可以。
int nDayts=static_cast<int>((ts.GetTotalSeconds()+86399)/86400);
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 );
time_t time=tm.GetTime(); //CTime--->time_t
CTimeSpan span(time);
span.GetDays();