<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. 【MySQL】binlog_format以及binlog事务记录分析

    MySQL官方对于binlog_format参数的说明: http://dev.mysql.com/doc/refman/5.5/en/binary-log-setting.html binlog_f ...

  2. [my]_ubuntu12.10_/etc/apt/sources.list

    deb http://mirrors.163.com/ubuntu/ precise main universe restricted multiverse deb-src http://mirror ...

  3. Mir2源码详解之服务端-选择(角色)网关(SelGate)

    其实,SelGate也就是 LoginGate,其源码实现完全相同.不必怀疑,市面上的都是这么做~!这里单独写这篇文章,就是为了说明这点!

  4. CentOS6.5下安装配置MySQL

    CentOS6.5下安装配置MySQL,配置方法如下: 安装mysql数据库:# yum install -y mysql-server mysql mysql-deve 查看mysql-server ...

  5. 如何解决Android的SDK与ADT不匹配问题

    win7/xp 下面安装Android虚拟机,更新SDK后,在Eclipse preference里指向android-sdk-windows时.出现 :This Android SDK requir ...

  6. 树莓派(Rospberry Pi B+)到货亲测

    1 图鉴 Rospberry Pi  B+终于在今天下午有蜗牛快递公司圆*送到了.B+主要是增加了2个USB,增加了GPIO,sd卡换成了micro sd ...先不说直接上图再说,期待了好久好久 整 ...

  7. POJ C程序设计进阶 编程题#1:寻找下标

    编程题#1:寻找下标 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描述 已知一 ...

  8. windows下如何修改远程登录端口

    windows下如何修改远程登录端口 windows远程桌面默认端口为3389,修改 方法如下:在"开始>运行"中输入"regedit" 点击“确定”,打 ...

  9. Silverlight DataGrid标题行居中

    1.引用命名空间 xmlns:Primitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Win ...

  10. SDUST 作业10 Problem D 魔方阵

    Description 所谓N阶魔方阵,是一个N*N的方阵,其元素由1到N^2组成,且方阵每行每列以及对角线的元素和相等.如三阶魔方阵: 8 1 6 3 5 7 4 9 2     魔方阵的规律如下: ...