直接使用加减,参考: // 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
注意时间差为CTimeSpan类对象,其提供了 GetDays —— Returns the number of complete days in this CTimeSpan. GetHours —— Returns the number of hours in the current day (–23 through 23). GetTotalHours —— Returns the total number of complete hours in this CTimeSpan. GetMinutes —— Returns the number of minutes in the current hour (–59 through 59). GetTotalMinutes —— Returns the total number of complete minutes in this CTimeSpan. GetSeconds —— Returns the number of seconds in the current minute (–59 through 59). GetTotalSeconds —— Returns the total number of complete seconds in this CTimeSpan. 这些函数用于获得时间的差值!
// 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
GetDays —— Returns the number of complete days in this CTimeSpan.
GetHours —— Returns the number of hours in the current day (–23 through 23).
GetTotalHours —— Returns the total number of complete hours in this CTimeSpan.
GetMinutes —— Returns the number of minutes in the current hour (–59 through 59).
GetTotalMinutes —— Returns the total number of complete minutes in this CTimeSpan.
GetSeconds —— Returns the number of seconds in the current minute (–59 through 59).
GetTotalSeconds —— Returns the total number of complete seconds in this CTimeSpan.
这些函数用于获得时间的差值!
GetCurrentTime获得当前时间
2.用clock()得到你的程序运行了多少时间;
3.init_time+clock()和系统时间进行比较,就能知道更改了多少.至于系统时间被更改后,重新初始化完毕,之后如何判断又被更改的时间,那就在设一个变量,记录之前更改量,修正init_time+clock(),之后就一样了。这是一个基本思路吧,具体看你的需要来写程序,相信能解决。