VC获取当前时间 (年月日,时分秒)
工具/原料
1
PC电脑一台
2
软件Visual C++
方法/步骤
1
打开Visual C++,点击菜单“文件”-“新建”-“工程”,输入工程名“GetCurrentTime”,点击“确定”。
2
选择“基于对话框”,点击“完成”。
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);}
5
编译,运行。点击按钮,即可看到标题栏上的时间显示。
注意事项
1
在其他版本的vc程序大同小异。
2
不支持Unicode。
上一篇:Windows电脑转换时区
下一篇:2020年欧洲杯赛程时间安排表