SYSTEMTIME 获取日期之差
#include <windows.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ATLComTime.h> #pragma once #pragma warning(disable:4996) int CompareSystemTime(SYSTEMTIME &stStart, SYSTEMTIME &stEnd) {//获取两个 SYSTEMTIME的日期之差 COleDateTime m_tStartDate; COleDateTime m_tEndDate; m_tStartDate.SetDate(stStart.wYear, stStart.wMonth, stStart.wDay); m_tEndDate.SetDate(stEnd.wYear, stEnd.wMonth, stEnd.wDay); COleDateTimeSpan nDays = m_tEndDate - m_tStartDate; return (int)nDays.GetDays(); } SYSTEMTIME GetDateAdded(SYSTEMTIME &stStart) {//起始日期增加一天 COleDateTime m_tStartDate; m_tStartDate.SetDate(stStart.wYear, stStart.wMonth, stStart.wDay); COleDateTimeSpan ts2(1); m_tStartDate += ts2; SYSTEMTIME stTemp; stTemp.wYear = m_tStartDate.GetYear(); stTemp.wMonth = m_tStartDate.GetMonth(); stTemp.wDay = m_tStartDate.GetDay(); return stTemp; } //主函数 int main(void) { SYSTEMTIME st, st1; st.wYear = 2014; st.wMonth = 12; st.wDay = 31; GetLocalTime(&st1); int nDays = CompareSystemTime(st, st1); printf("%d\n", nDays); st = GetDateAdded(st); printf("%d-%02d-%02d\n", st.wYear, st.wMonth, st.wDay); nDays = CompareSystemTime(st, st1); printf("%d\n", nDays); return 0; }