VC++编程中获取系统时间
<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++编程中获取系统时间的更多相关文章
- Linux驱动中获取系统时间
最近在做VoIP方面的驱动,总共有16个FXS口和FXO口依次初始化,耗用的时间较多.准备将其改为多线程,首先需要确定哪个环节消耗的时间多,这就需要获取系统时间. #include <linux ...
- Java中获取系统时间的四种方式
第一种: Date day=new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" ...
- java总结:Java中获取系统时间(年、月、日)以及下拉菜单默认选择系统年、月、日的方法
<!-- 获取系统当前的年.月.日 --> <%@ page import="java.util.*"%> <% Calendar calendar= ...
- linux中获取系统时间的几种方法
asctime(将时间和日期以字符串格式表示) 相关函数 time,ctime,gmtime,localtime 表头文件 #include<time.h> 定义函数 char * asc ...
- linux中获取系统时间 gettimeofday函数
linux的man页中对gettimeofday函数的说明中,有这样一个说明: $ man gettimeofday DESCRIPTION The functions gettimeof ...
- Linux编程(获取系统时间)
#include <stdio.h> #include <time.h> int main() { time_t now; struct tm *w; time(&no ...
- Java 中的系统时间
currentTimeMillis()System.currentTimeMillis返回的是从1970.1.1 UTC 零点开始到现在的时间,精确到毫秒,平时我们可以根据System.current ...
- Android获取系统时间的多种方法
Android中获取系统时间有多种方法,可分为Java中Calendar类获取,java.util.date类实现,还有android中Time实现. 现总结如下: 方法一: ? 1 2 3 4 5 ...
- Mysql获取系统时间,年,月,日
Mysql数据库中获取系统时间,年,月,日单个获取 获取当前系统日期时间:select SYSDATE() AS 系统日期时间; 获取当前系统年月日:select current_date AS ...
随机推荐
- 【Linux】自动化部署可信任登录
Linux信任登录,免密码登录的脚本: 需要安装expect,可以yum也可以编译安装,编译后注意脚本中的expect路径. rsa.exp #!/usr/bin/expect ########### ...
- sql 时间向减函数
select datediff(d, ( select isnull( ( select v.VerifyDate from T_VerifySituation v where Orde ...
- c++ builder TListView控件按字符串排序(根据网上代码亲测ok)
//--------------------------------------------------------------------------- /* 首先将一个列表框控件安放在Form上, ...
- 破解Demo
需要破解的程序界面如下: 需要破解的程序的主要代码如下: void CEasyCrackMeDlg::OnBnClickedButtonOk() { // TODO: 在此添加控件通知处理程序代码 T ...
- Raspberry Pi B+ 定时向物联网yeelink上传CPU GPU温度
Raspberry Pi B+ 定时向物联网yeelink上传CPU GPU温度 硬件平台: Raspberry Pi B+ 软件平台: Raspberry 系统与前期安装请参见:树莓派(Ros ...
- html5,html5教程
html5,html5教程 1.向后兼容 HTML5是这样被定义的:能向后兼容目前UA处理内容的方式.为了让语言更简单,一些老的元素和Attribute被舍弃.比如一些纯粹用于展现的元素(译注:即非语 ...
- UISearchBar去除背景颜色
UISearchBar *searchBar=[[UISearchBar alloc]initWithFrame:frame]; //这个设置背景透明可能无效 searchBar.background ...
- 使用MySQL数据库
登录到MySQL 当 MySQL 服务已经运行时, 我们可以通过MySQL自带的客户端工具登录到MySQL数据库中, 首先打开命令提示符, 输入以下格式的命名: mysql -h 主机名 -u 用户名 ...
- PHP多例模式
学习java就知道设计模式中有多例模式: 1.多例类可以有多个实例2.多例类必须能够自我创建并管理自己的实例,并向外界提供自己的实例. 大家都知道PHP单例模式,却很少说PHP多例模式,下面是在wik ...
- php 购物车的例子
网上搜到的,简单容易理解.cookie存购物车ID,db存购物车数据. //购物车session的产生代码 1 if(! $session && ! $scid) { 2 / ...