原贴地址:
http://topic.csdn.net/t/20040707/08/3151675.html
我稍微加工了一下:
====================Begin====================
int GetDiffSeconds(const SYSTEMTIME &t1, const SYSTEMTIME &t2)
{
FILETIME fTime1 = { 0, 0 };
FILETIME fTime2 = { 0, 0 };
SystemTimeToFileTime(&t1, &fTime1);
SystemTimeToFileTime(&t2, &fTime2);
time_t tt1 = FileTimeToTime_t(fTime1);
time_t tt2 = FileTimeToTime_t(fTime2);
return (int)(tt2 – tt1);
}
int GetDiffDays(const SYSTEMTIME &t1, const SYSTEMTIME &t2)
{
int diffSeconds = GetDiffSeconds(t1, t2);
return diffSeconds / (24 * 3600);
}
====================End====================
// 我顺便补充一个:反推SYSTEMTIME隔N天之后的SYSTEMTIME
void GetOffsetDaysTime(const SYSTEMTIME &stSrc, int offDays, SYSTEMTIME &stDst)
{
FILETIME fTimeSrc = { 0, 0 };
SystemTimeToFileTime(&stSrc, &fTimeSrc);
time_t tmSrc = FileTimeToTime_t(fTimeSrc);
time_t tmDst = tmSrc + SEC_OF_DAY * offDays;
FILETIME fTimeDst = { 0, 0 };
Time_tToFileTime(fTimeDst, tmDst);
FileTimeToSystemTime(&fTimeDst, &stDst);
}