Original posted Address:
Http://topic.csdn.net/t/20040707/08/3151675.html
I processed it a little bit:
====================begin====================
time_t FileTimeToTime_t(const FILETIME &ft)
{
ULARGE_INTEGER ui;
ui.LowPart = ft.dwLowDateTime;
ui.HighPart = ft.dwHighDateTime;
return ((LONGLONG)(ui.QuadPart - 116444736000000000) / 10000000);
}
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====================
By the way, I'll add one: reverse-push SYSTEMTIME after N-day systemtime
void Time_tToFileTime(FILETIME &ft, time_t time)
{
ULARGE_INTEGER ui;
ui.QuadPart = (LONGLONG)(time * 10000000) + (LONGLONG)(116444736000000000);
ft.dwLowDateTime = ui.LowPart;
ft.dwHighDateTime = ui.HighPart;
}
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);
}