<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. 织梦DedeCMS列表摘要 description 长度控制方法

    [field:description /]标签如何限制字数? [field:description function='cn_substr(@me,80)'/] DedeCMS 里的所有标记都支持这样 ...

  2. console数据

  3. 如何根据IP查找计算机名

    示例:nbtstat -A  192.168.1.123 参考网址:http://jingyan.baidu.com/article/335530daa40d7f19cb41c312.html

  4. Android IOS WebRTC 音视频开发总结(四三)-- 诚信交易案例分享

    本文主要记录一些诚信交易的案例(两个陌生人之间没有合同,没有订金,没有讨价还价,完全靠诚信完成的交易), 特别纪录下来并不是因为金额有多高,而是因为在现在这种社会要完成这样的交易太难,特别是像咨询这种 ...

  5. 安装minicom串口访问开发板

    1. 安装minicom yum install minicom   2. 设置minicom minicom -s 选择“Serial port setup”,将“Serial Device”修改成 ...

  6. PeopleSoft Object Types Definitions

     PeopleSoft stores object definitions types such as Record, Field and SQL definitions as numbers in  ...

  7. C#实现图书馆程序导入ISO-2709格式(MARC)功能

    1.导入 /// <summary> /// 导入ISO2709 /// </summary> /// <param name="sender"> ...

  8. WindowsApi 解压缩文件

    .解压方法 转载自http://www.2cto.com/kf/201204/128704.html "C#解压.zip文件,网上一搜一大堆方法,有使用System.IO.Compressi ...

  9. linux expect初识

    写个命令,让ssh服务器便捷点 #!/usr/bin/expect set type [lindex $argv 0] if {$type == "server"} { set i ...

  10. Java do while求和

    用do while结构求0~100的整数数字之和. 代码如下: public class DoWhileDemo { public static void main(String[] args) { ...