编写c++程序来计算任何两个日期之间的天数和

2024-12-01 10:52:55
推荐回答(1个)
回答1:

编译平台:Visual Studio 2005 Visual C++

COleDateTime t1( 1999, 3, 19, 22, 15, 0 ); // 10:15PM March 19, 1999
COleDateTime t2( 1999, 3, 20, 22, 15, 0 ); // 10:15PM March 20, 1999

// Subtract 2 COleDateTimes
COleDateTimeSpan ts = t2 - t1;

// one day is 24 * 60 * 60 == 86400 seconds
ASSERT( ts.GetTotalSeconds() == 86400L );
ASSERT( ts.GetTotalDays() == 1)

// Add a COleDateTimeSpan to a COleDateTime.
ASSERT( ( t1 + ts ) == t2 );

// Subtract a COleDateTimeSpan from a COleDateTime.
ASSERT( ( t2 - ts ) == t1 );