转自:http://blog.csdn.net/fzuim/article/details/61199351
涉及到有效期的设置,需要计算N天时间间隔的时间。
C++ Code
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#define QUADPART 10000000i64
SYSTEMTIME CalTime(int nTimeSpan) { SYSTEMTIME sysCurTime; SYSTEMTIME sysOutTime; GetLocalTime(&sysCurTime); LONGLONG lTimeSpan = nTimeSpan * QUADPART * 86400; LARGE_INTEGER fTime; SystemTimeToFileTime(&sysCurTime, (FILETIME*)&fTime); fTime.QuadPart += lTimeSpan; FileTimeToSystemTime((FILETIME*)&fTime, &sysOutTime); return sysOutTime; } |
上面代码就只计算天数间隔,若要类似CTimeSpan( LONG lDays, int nHours, int nMins, int nSecs )计算到时分秒,则传参需要采用类似CTimeSpan类的方式构造个CArTimeSpan( LONG lDays, int nHours, int nMins, int nSecs );用成员变量存储对应的天时分秒
C++ Code
1
2 3 4 |
LONGLONG lTimeSpan = v_ArTimeSpan.m_iDays * QUADPART * 86400 +
v_ArTimeSpan.m_iHours * QUADPART * 3600 + v_ArTimeSpan.m_iMins * QUADPART * 60 + v_ArTimeSpan.m_iSecs * QUADPART; |