VC获取当前时间(年月日,时分秒)

2025-04-08 08:25:14

1、打开Visual C++,点击菜单“文件”-“新建”-“工程”,输入工程名“GetCurrentTime”,点击“确定”。

VC获取当前时间(年月日,时分秒)

2、选择“基于对话框”,点击“完成”。

VC获取当前时间(年月日,时分秒)

3、加入一个按钮Button1,并双击,点击“确定”进去。

VC获取当前时间(年月日,时分秒)

4、加入代码如下:void CGetCurrentTimeDlg::OnButton1(){ // TODO: Add your 艘早祓胂control notification handler code here char szTime[32]; CTime time; time = CTime::GetCurrentTime(); sprintf(szTime, "%4d-%.2d-%.2d %.2d:%.2d:%.2d", time.GetYear(), time.GetMonth(), time.GetDay(), time.GetHour(), time.GetMinute(), time.GetSecond()); SetWindowText(szTime);}

VC获取当前时间(年月日,时分秒)

5、编译,运行。点击按钮,即可看到标题栏上的时间显示。

VC获取当前时间(年月日,时分秒)
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢