第一种方法:
CTime 和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
第二种方法:
先转换成COleDateTime类,用这两个类对象减得到COleTimeSpan类型,即可,我一直这么用的。
SYSTEMTIME &stTimeF;
SYSTEMTIME &stTimeS;
。。。。。。。。。。。
COleDateTime dTimeF(stTimeF);
COleDateTime dTimeS(stTimeS);
COleDateTimeSpan dTimeSpan = dTimeF - dTimeS;
int nSecnonSpan = dTimeSpan.GetTotalSeconds();
第三种方法:
SYSTEMTIME sTime1;
SYSTEMTIME sTime2;
...
...
ULARGE_INTEGER fTime1;/*FILETIME*/
ULARGE_INTEGER fTime2;/*FILETIME*/
SystemTimeToFileTime(&sTime1,(FILETIME*)&fTime1);
SystemTimeToFileTime(&sTime2,(FILETIME*)&fTime2);
unsigned __int64 dft=fTime2.QuadPart-fTime1.QuadPart;
第四种方法:
SYSTEMTIME sTime1;
GetLocalTime(&sTime1);
printf("Local System Time(YYYY-MM-DD HH:MM:SS): %d-%d-%d %d:%d:%d\n", sTime1.wYear, sTime1.wMonth,
sTime1.wDay, sTime1.wHour, sTime1.wMinute, sTime1.wSecond);
ULARGE_INTEGER fTime1;/*FILETIME*/
SystemTimeToFileTime(&sTime1,(FILETIME*)&fTime1);
unsigned __int64 dft=864000000000*5;
fTime1.QuadPart=fTime1.QuadPart+dft;
FileTimeToSystemTime((FILETIME*)&fTime1, &sTime1);
printf("UTC System Time2 (YYYY-MM-DD HH:MM:SS): %d-%d-%d %d:%d:%d\n", sTime1.wYear, sTime1.wMonth,
sTime1.wDay, sTime1.wHour, sTime1.wMinute, sTime1.wSecond);