MFC获取系统时间的方法
来源:互联网 发布:澳洲工资算法 编辑:程序博客网 时间:2024/06/08 07:15
在存储录音文件名称时,为避免生成录音文件名重名而覆盖先前的录音文件,用到了添加系统时间作为名称后缀 的方法。系统时间应用场合也比较多,例如生产随机数的种子等。这里的避免文件名重名而作为名称后缀等等。这里关于系统时间也做一个小结。
简要地介绍一下搜集到的几种获取系统时间的方法。(注:整理源于网络)
1) 使用CTime类
CString str; //获取系统时间 CTime tm; tm = CTime::GetCurrentTime();str= tm.Format(_T("现在时间是%Y年%m月%d日 %X")); MessageBox(str,NULL,MB_OK);
2) 得到系统时间日期(使用GetLocalTime)
SYSTEMTIME st;CString strDate,strTime;GetLocalTime(&st);strDate.Format(_T("%4d-%2d-%2d"),st.wYear,st.wMonth,st.wDay);MessageBox(strDate,NULL,MB_OK);strTime.Format(_T("%2d:%2d:%2d"),st.wHour,st.wMinute,st.wSecond);MessageBox(strTime,NULL,MB_OK);
3) 使用GetTickCount获取程序运行时间
long t1=GetTickCount();//程序段开始前取得系统运行时间(ms)Sleep(500); CString str,str1;long t2=GetTickCount();//程序段结束后取得系统运行时间(ms) str.Format(_T("time:%dms"),t2-t1);//前后之差即 程序运行时间AfxMessageBox(str);//获取系统运行时间long t=GetTickCount(); str1.Format(_T("系统已运行 %d时"),t/3600000);str=str1;t%=3600000; str1.Format(_T("%d分"),t/60000); str+=str1; t%=60000; str1.Format(_T("%d秒"),t/1000); str+=str1; AfxMessageBox(str);
获取系统时间方法相对简单,根据自己的情况选择对应的方法即可。
0 0
- MFC获取系统当前时间的方法
- MFC获取系统时间的几个方法
- MFC获取系统时间的方法
- mfc获取系统时间方法
- MFC 获取系统时间
- MFC 获取系统时间
- MFC获取系统时间
- MFC获取系统时间
- MFC 获取系统时间
- MFC 获取系统时间
- MFC 获取系统时间
- MFC获取系统时间
- MFC获取系统时间
- MFC获取系统时间
- mfc获取系统时间
- 获取系统时间的方法
- MFC获取时间的几种方法
- MFC中获得系统时间的方法
- ocos2d-x游戏实例之忍者飞镖——添加其他元素
- poj1703 种类并查集
- 主机pci设备直通
- hdu_1026
- s3c2440_MMU(1)
- MFC获取系统时间的方法
- 如何用Linux命令行管理网络:11个你必须知道的命令
- 分别用pfile 生成spfile 和用spfile 生成pfile;分别用这两个参数启动数据库。
- JavaEE的13种核心技术
- Oracle 归档与非归档的切换
- 寻找数组中的第k个数(序)
- CMake实践
- 第一周项目三某天是该年的第几天
- 误删除日志文件导致出现 ORA-01034&ORA-27101错误