MFC获取系统当前时间
1.使用CTime类
CString str; //获取系统时间
CTime tm;
tm=CTime::GetCurrentTime();
str=tm.Format("现在时间是%Y年%m月%d日 %X");
//CString strTime = t.Format(_T( "%Y-%m-%d %H:%M:%S"));
MessageBox(str,NULL,MB_OK);
2: 得到系统时间日期(使用GetLocalTime)
SYSTEMTIME st;
CString strDate,strTime;
GetLocalTime(&st);
strDate.Format("%4d-%2d-%2d",st.wYear,st.wMonth,st.wDay);
strTime.Format("%2d:%2d:%2d",st.wHour,st.wMinute,st.wSecond);
3.使用GetTickCount//获取程序运行时间
long t1=GetTickCount();//程序段开始前取得系统运行时间(ms)
Sleep(500); long t2=GetTickCount();//程序段结束后取得系统运行时间(ms)
str.Format("time:%dms",t2-t1);//前后之差即 程序运行时间
AfxMessageBox(str);//获取系统运行时间
long t=GetTickCount();
CString str,str1;
str1.Format("系统已运行 %d时",t/3600000);
str=str1; t%=3600000;
str1.Format("%d分",t/60000);
str+=str1; t%=60000;
str1.Format("%d秒",t/1000);
str+=str1; AfxMessageBox(str);
在定时器中添加代码,定时器设置成一秒一次。
CTime t = CTime::GetCurrentTime();
CString strTime = t.Format(_T( "%Y-%m-%d %H:%M:%S"));
在界面上加一个编辑控件或者静态文本控件,再添加代码将 strTime 显示到控件中。
SetDlgItemText(IDD_YOURCTRL, strTime);
新建一个基于对话框的MFC程序,设置都取默认值。
一、在“OnInitDialog()”函数的“return TRUE;”前加上以下代码:
SetTimer(1, 1000, NULL);
二、添加 WM_TIMER 消息映射(不要告诉我你不会-_-||),然后在OnTimer函数里添加以下代码:
CTime tm = CTime::GetCurrentTime();
CString str = tm.Format("%H:%M:%S");
SetWindowText(str); // 设置对话框的标题为当前时间
另:
OnTimer函数是使用类向导添加的。添加方法如下:
按“Ctrl+W”打开“MFC ClassWizard”对话框,
在“Message Maps”页,“Project”下拉框应该就一个工程,
“Class Name”下拉框选名称为“C***Dlg”的,
“Object IDs”列表框也选名称为“C***Dlg”的,
“Messages”列表框里选择“WM_TIMER”,
然后点右边的按钮“Add Function”,再点“Edit Code”,
就会自动添加OnTimer函数并定位到OnTimer函数里。
其实很简单 就是建立一个 dialog 工程
然后 添加 WM_TIMER函数 一次性搞定
我可以给你源码 MFC的东西 不看整个工程很难搞清楚的
至于说的在OnInitDialog中 添加SetTimer(100,1000,NULL);
其实意思是在程序运行时调用 SetTimer(100,1000,NULL);函数
MFC获取系统当前时间的更多相关文章
- MFC获取系统当前时间的几种方法
1.使用CTime类 CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime(); str=tm.Format("现在时间是%Y年% ...
- java获取系统指定时间年月日
java获取系统指定时间年月日 private String setDateTime(String falg) { Calendar c = Calendar.getInstance(); c.set ...
- Unity3D获取系统当前时间,并格式化显示
Unity 获取系统当前时间,并格式化显示.通过“System.DateTime”获取系统当前的时间,然后通过格式化把获得的时间格式化显示出来,具体如下: 1.打开Unity,新建一个空工程,Unit ...
- Oracle,MySQL,sqlserver三大数据库如何获取系统当前时间
Oracle中如何获取系统当前时间:用SYSDATE() MySQL中获取系统当前时间主要有以下几点: (1)now()函数以('YYYY-MM-dd HH:mm:SS')返回当前的日期时间,可以直接 ...
- java 获取系统当前时间并格式化
java 获取系统当前时间并格式化 CreateTime--2018年5月9日11:41:00 Author:Marydon 实现方式有三种 updateTime--2018年7月23日09点32 ...
- 使用js时,如何获取系统当前时间并且得到格式为"yyyy年MM月"的日期
1.使用js时,如何获取系统当前时间并且得到格式为"yyyy年MM月"的日期: 1 var newdate = new Date(); 2 var nowyear = newdat ...
- C++ 获取系统当前时间(日历时)
获取系统当前时间(日历时) //Linux & C++11 #include <chrono> #include <ctime> using namespace std ...
- android service 样例(电话录音和获取系统当前时间)
关于android service 的具体解释请參考: android四大组件--android service具体解释.以下将用两个实例具体呈现Android Service的两种实现. 一个是st ...
- C# 获取系统开机时间
原文:C# 获取系统开机时间 /// /// 获取系统开机时间 /// /// private DateTime GetComput ...
随机推荐
- jquery 获取css position的值
jquery 获取css position的值 CreateTime--2018年5月28日14:03:12 Author:Marydon 1.情景展示 <div id="aa&q ...
- Android 自己定义View (四) 视频音量调控
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/24529807 今天没事逛eoe,看见有人求助要做一个以下的效果,我看以下一哥们说 ...
- INFORMIX的dbexport和dbimport使用示例说明
INFORMIX-IDS数据库进行迁移中,我们在进行数据级别的迁移时,采用dbexport,dbimport来完成.dbexport导出数据库中所有对象的模式脚本和表数据文件,该模式脚本中包含有表等的 ...
- AngularJS 中的作用域
问题引入 使用 Angular 进行过一段时间的开发后,基本上都会遇到一个这样的坑: 123456789101112 <div ng-controller="TestCtrl" ...
- sql查看所有表大小的方法
sql查看所有表大小的方法. 代码: declare @id int ) declare @pages int declare @dbname sysname ,) ,) ,) create tabl ...
- 安卓-APP安装后多个图标的解决
原因是在不同Activity的intent中配置了多个LAUNCHER. <intent-filter> <action android:name="android.int ...
- android对话框,checkBox,同一时候在同一个页面上保存数据
package com.example.selectonlyonle; import android.app.Activity; import android.app.AlertDialog; imp ...
- KVM部署LVS集群故障案例一则
一.故障现象 KVM部署LVS(Linux Virtual Server)集群后,能够单独以HTTP方式访问RS(Real Server)的实际IP,但无法通过VIP(Virtual IP)访问. 二 ...
- 在linux平台下,设置core dump文件属性(位置,大小,文件名等)
在linux平台下,设置core dump文件生成的方法: 1) 在终端中输入ulimit -c 如果结果为0,说明当程序崩溃时,系统并不能生成core dump. 2) 使用ulimit -c un ...
- android BaseAdapter getView 理解
ListView是安卓中很经常使用的一个控件. 安卓设计使用Adapter来对ListView进行管理. 可是系统提供的Adapter无法满足一些复杂的显示情况,这个时候我们就须要使用BaseAdap ...