/ 起始和结束日期时间 变量
COleDateTime m_tStartDate;
COleDateTime m_tStartTime;
COleDateTime m_tEndDate;
COleDateTime m_tEndTime;
// 格式化后的起始和结束的日期时间变量
COleDateTime m_tStartDateTime;
COleDateTime m_tEndDateTime;
void CalDlg::OnCalculate()
{
// TODO: Add your control notification handler code here
UpdateData();
// 格式化起始和结束的日期时间
m_tStartDateTime.SetDateTime(
m_tStartDate.GetYear(),
m_tStartDate.GetMonth(),
m_tStartDate.GetDay(),
m_tStartTime.GetHour(),
m_tStartTime.GetMinute(),
m_tStartTime.GetSecond());
m_tEndDateTime.SetDateTime(
m_tEndDate.GetYear(),
m_tEndDate.GetMonth(),
m_tEndDate.GetDay(),
m_tEndTime.GetHour(),
m_tEndTime.GetMinute(),
m_tEndTime.GetSecond());
COleDateTimeSpan tMinute = m_tEndDateTime - m_tStartDateTime; // 计算两个日期时间的差值
int iMinute = (int)tMinute.GetTotalMinutes();
CString strMinute = _T("");
strMinute.Format("%d", iMinute);
MessageBox(strMinute);
}
获得当前时间:
SYSTEMTIME sysTm;
::GetLocalTime(&sysTm);
m_tStartDateTime.SetDateTime(sysTm.wYear,sysTm.wMonth,sysTm.wDay,sysTm.wHour,sysTm.wMinute,sysTm.wSecond);