<span style="white-space:pre">	</span>总结了在程序中如何获得系统时间的方法
void CGetSystenTimeDlg::OnBnClickedGettimeButton()
{
// TODO: 在此添加控件通知处理程序代码
//方法一 使用MFC的CTime类
CString str; //获取系统时间
CTime tm; tm=CTime::GetCurrentTime();
str=tm.Format("现在时间是%Y年%m月%d日 %X"); MessageBox(str,NULL,MB_OK); ////方法二 使用win32定义得结构体
SYSTEMTIME time;
CString str1,str2;
GetLocalTime(&time); //Windows API 函数,用来获取当地的当前系统日期和时间。
str1.Format(L"%d-%d-%d",time.wYear,time.wMonth,time.wDay);
str2.Format(L"%2d:%2d:%2d",time.wHour,time.wMinute,time.wSecond);
MessageBox(str1,NULL,MB_OK);
MessageBox(str2,NULL,MB_OK); //方法三:GetTickCount返回(retrieve)从操作系统启动所经过的毫秒数
//,它的返回值是DWORD。 可以用它来测量程序的运行时间
CString str3;
long t1=GetTickCount();//程序段开始前取得系统运行时间(ms)   
Sleep(500);
long t2=GetTickCount();//程序段结束后取得系统运行时间(ms)   
str3.Format(L"time:%dms",t2-t1);//前后之差即 程序运行时间   
AfxMessageBox(str3);//获取系统运行时间   即休眠的的时间  //从操作系统启动所经过的时间
long t=GetTickCount();
CString str4;
CString str5;
str4.Format(L"系统已运行 %d时",t/3600000);
str5=str5+str4;
// MessageBox(str4,NULL,MB_OK);
t%=3600000; str4.Format(L"系统已经运行 %d分",t/60000);
str5=str5+str4;
t%=60000;
str4.Format(L"系统已经运行 %d秒",t/1000);
str5=str5+str4; MessageBox(str5,NULL,MB_OK); }

方法一:

方法二:

      

方法三:

VC++编程中获取系统时间的更多相关文章

  1. Linux驱动中获取系统时间

    最近在做VoIP方面的驱动,总共有16个FXS口和FXO口依次初始化,耗用的时间较多.准备将其改为多线程,首先需要确定哪个环节消耗的时间多,这就需要获取系统时间. #include <linux ...

  2. Java中获取系统时间的四种方式

    第一种: Date day=new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" ...

  3. java总结:Java中获取系统时间(年、月、日)以及下拉菜单默认选择系统年、月、日的方法

    <!-- 获取系统当前的年.月.日 --> <%@ page import="java.util.*"%> <% Calendar calendar= ...

  4. linux中获取系统时间的几种方法

    asctime(将时间和日期以字符串格式表示) 相关函数 time,ctime,gmtime,localtime 表头文件 #include<time.h> 定义函数 char * asc ...

  5. linux中获取系统时间 gettimeofday函数

    linux的man页中对gettimeofday函数的说明中,有这样一个说明:   $ man gettimeofday DESCRIPTION     The functions gettimeof ...

  6. Linux编程(获取系统时间)

    #include <stdio.h> #include <time.h> int main() { time_t now; struct tm *w; time(&no ...

  7. Java 中的系统时间

    currentTimeMillis()System.currentTimeMillis返回的是从1970.1.1 UTC 零点开始到现在的时间,精确到毫秒,平时我们可以根据System.current ...

  8. Android获取系统时间的多种方法

    Android中获取系统时间有多种方法,可分为Java中Calendar类获取,java.util.date类实现,还有android中Time实现. 现总结如下: 方法一: ? 1 2 3 4 5 ...

  9. Mysql获取系统时间,年,月,日

      Mysql数据库中获取系统时间,年,月,日单个获取 获取当前系统日期时间:select SYSDATE() AS 系统日期时间; 获取当前系统年月日:select current_date AS ...

随机推荐

  1. ERDAS 2013与ArcGIS10.1安装时的兼容性问题

    在Regedit中HKEY_LOCAL_MACHINE->SOFTWARE->FLEXlm License Manager下新建一个“ERDAS License Manager”,然后按照 ...

  2. druid parser

    有没有好用的开源sql语法分析器? - 匿名用户的回答 - 知乎 druid parser

  3. How to index email and attachments in nsf files?

    My colleague she ask me why Intella could not handle Lotus Notes nsf e-mail archive files. I told he ...

  4. Cent OS yum 安装 Adobe flash player

    桌面打开浏览器访问:http://get.adobe.com/cn/flashplayer/.网页会判断操作系统和浏览器并下载 Flash Player(支持Firefox浏览器). 或者直接下载: ...

  5. leetcode 21

    合并两个有序数列.属于基础的数据结构问题,核心在于对链表的操作. 代码如下: /** * Definition for singly-linked list. * struct ListNode { ...

  6. 动态设置屏幕icon

    REPORT demo_dynpro_status_icons.     DATA value TYPE i VALUE 1.     DATA: status_icon TYPE icons-tex ...

  7. DataTable.Select

    转载请注明出处:http://www.cnblogs.com/havedream/p/4453297.html 方法:DataTable.Select 作用:获取 DataRow 对象的数组. 重载: ...

  8. 三种找回 linux root密码

    找回 linux root密码的三种方法 第1种方法: 1.在系统进入单用户状态,直接用passwd root去更改2.用安装光盘引导系统,进行linux rescue状态,将原来/分区挂接上来,作法 ...

  9. Internet Explorer 无法启用 JavaScript 怎么办?

    在 Internet Expllorer 8/9 中,有些同学在浏览网页时,收到提示:“需要启用 JavaScript …”,并且会发现网页上某些功能不能用了,比如点击网页里的按钮没反应等等. 怎么启 ...

  10. 一元三次方程 (codevs 1038)题解

    [问题描述] 有形如:ax3+bx2+cx+d=0这样的一个一元三次方程.给出该方程中各项的系数(a,b,c,d均为实数),并约定该方程存在三个不同实根(根的范围在-100至100之间),且根与根之差 ...