MFC中兩種方法獲取系統時間
阿新 • • 發佈:2018-12-18
void CMFC2Dlg::OnBnClickedButton1() { // TODO: 在此新增控制元件通知處理程式程式碼 CTime t = CTime::GetCurrentTime(); int nYear=t.GetYear(); int nMonth=t.GetMonth(); int nDay = t.GetDay(); int nHour =t.GetHour(); int nMin=t.GetMinute(); int nSec=t.GetSecond(); int nWeek=t.GetDayOfWeek(); CString str; str.Format("當前時間是:%02d年%02d月%02d日 %02d:%02d:%02d",nYear,nMonth,nDay,nHour,nMin,nSec); // AfxMessageBox(str); this ->SetWindowText(str); } void CMFC2Dlg::OnBnClickedButton2() { // TODO: 在此新增控制元件通知處理程式程式碼 time_t tt=time(NULL); tm *pTime=localtime(&tt); int nYear=pTime->tm_year+1900; int nMonth=pTime->tm_mon+1; int nDay = pTime->tm_yday; int nHour =pTime->tm_hour; int nMin=pTime->tm_min; int nSec=pTime->tm_sec; CString str; str.Format(" 當前時間是:%02d年%02d月%02d日 %02d:%02d:%02d",nYear,nMonth,nDay,nHour,nMin,nSec); // AfxMessageBox(str); this ->SetWindowText(str); }