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);
}
MFC中两种方法获取系统时间
猜你喜欢
转载自blog.csdn.net/suntingsheng123/article/details/84403149
今日推荐
周排行