获取系统时间的几种方法,最高精确1ms
来源:互联网 发布:数据透视表页字段在哪 编辑:程序博客网 时间:2024/05/16 07:28
●【获取系统时间的几种方法,最高精确1ms】
1.硬件支持高精度计时器 ( 精确到1ms )
//获取的最准确,精确到1msLARGE_INTEGER nFreq;LARGE_INTEGER nBeginTime;LARGE_INTEGER nEndTime;double time;QueryPerformanceFrequency(&nFreq);QueryPerformanceCounter(&nBeginTime); QueryPerformanceCounter(&nEndTime);time = (double)(nEndTime.QuadPart - nBeginTime.QuadPart) / (double)nFreq.QuadPart;CString str;str.Format("%lf", time);MessageBoxA(str);
2.使用CTime类
CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime(); str=tm.Format("现在时间是%Y年%m月%d日 %X");MessageBox(str,NULL,MB_OK);
3: 得到系统时间日期(使用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);
4.使用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);
0 0
- 获取系统时间的几种方法,最高精确1ms
- 精确到ms级别的获取系统时间办法
- WinCe下获取系统时间的API函数(精确到ms级)
- VC获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法
- VC获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法
- VC获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法
- VC获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法
- VC获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法
- VC获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法
- VC++ 获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法
- VC获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法
- 编程 获取系统时间的几种方法
- Java获取系统时间的几种方法
- Java获取系统时间的几种方法
- Java获取系统时间的几种方法
- Java获取系统时间的几种方法
- java 获取系统时间的几种方法
- Java获取系统时间的几种方法
- php 在mac上为php添加pcntl扩展
- RabbitMQ学习之Linux下安装(一)
- C++高手必看书籍
- http://blog.jobbole.com/99911/#comment-156399
- android source camera
- 获取系统时间的几种方法,最高精确1ms
- iOS 使用学习笔记1
- SecurityError: The operation is insecure.
- 跨平台AR增强现实开发(二)(Vuforia目录结构)
- LeetCode 278. First Bad Version
- 我的iOS工程结构
- 遇见你,爱上你——--献给奇查最美的情书
- OpenCv学习笔记(七)---OpenCv中的基本绘图函数,圆,椭圆,线段,矩形,多边形的绘制(1)
- 设计模式之六大原则——开闭原则(OCP)