vc 获取当前时间
1.使用CTime类
CString str;
//获取系统时间
CTime tm;
tm=CTime:: GetCurrentTime_r();
str=tm.Format("现在时间是%Y年%m月%d日 %X");
MessageBox(str,NULL,MB_OK);
2: 得到系统时间日期(使用GetLocalTime)
SYSTEMTIME st;
CString strDate,strTime;
GetLocalTime_r(&st);
strDate.Format("%4d-%2d-%2d",st.wYear,st.wMonth,st.wDay);
strTime.Format("%2d:%2d:%2d",st.wHour,st.wMinute,st.wSecond);
3.使用GetTickCount
//获取程序运行时间
long t1= GetTickCount_r();//程序段开始前取得系统运行时间(ms)
//long t1= GetTickCount();
//Sleep(500);
long t2= GetTickCount_r();();//程序段结束后取得系统运行时间(ms)
//long t2= GetTickCount();
str.Format("time:%dms",t2-t1);//前后之差即程序运行时间
AfxMessageBox(str);
4.获取系统运行时间
long t= GetTickCount_r();
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);
5.计算从1970年1月1日0时0分0秒到该时间点所经过的秒数
#include<iostream>
#include<ctime>
using namespace std;
int main(){
time_t now_time;
now_time = time(NULL);
cout<<now_time;
return 0;
}
6.利用系统函数改变电脑的时间设定
#include<stdlib.h>
#include<iostream>
using namespace std;
void main(){
system("time");
}
vc 获取当前时间的更多相关文章
- vc 获取当前时间 (zhuan)
vc 获取当前时间(2010-02-10 11:34:32) http://wenku.baidu.com/view/6ade96d049649b6648d7475e.html 1.使用CTime类 ...
- VC++ 获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法
1.使用CTime类(获取系统当前时间,精确到秒) CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();//获取系统日期 str=tm ...
- 【VS开发】VC++ 获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法
1.使用CTime类(获取系统当前时间,精确到秒) CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();//获取系统日期 str=tm ...
- VC获取精确时间的做法
声明:本文章是我整合网上的资料而成的,其中的大部分文字不是我所为的,我所起的作用只是归纳整理并添加我的一些看法.非常感谢引用到的文字的作者的辛勤劳动,所参考的文献在文章最后我已一一列出. 对关注性能的 ...
- vc 获取网络时间
方式1 : #include <WinSock2.h> #include <Windows.h> #pragma comment(lib, "WS2_32" ...
- VC中如何获取当前时间(精度达到毫秒级)
标 题: VC中如何获取当前时间(精度达到毫秒级)作 者: 0xFFFFCCCC时 间: 2013-06-24链 接: http://www.cnblogs.com/Y4ng/p/Millisecon ...
- VC++编程中获取系统时间
<span style="white-space:pre"> </span>总结了在程序中如何获得系统时间的方法 void CGetSystenTimeDl ...
- C/C++获取系统时间
C/C++获取系统时间需要使用Windows API,包含头文件"windows.h". 系统时间的数据类型为SYSTEMTIME,可以在winbase.h中查询到如下定义: ty ...
- 获取当前时间并格式化,CTime类
CTime类,此类应该不是C++标准类库,属于windows封装的关于时间的类库,使用环境应该为 Win32程序,MFC程序,VC++程序 CTime tm = CTime::GetCurrentTi ...
随机推荐
- MySQL学习笔记(5) - 修改和删除数据库
1.完整语句 ALTER {DATABASE | SCHEMA} [db_name] [DEFAULT] CHARACHER SET [=] charset_name; 2.修改数据库的编码方式 al ...
- Android学习笔记--Menu菜单的使用
实现选项菜单.上下文菜单,以及菜单内部的子菜单. 视图效果: MainActivity 选项菜单 选项菜单的子菜单 上下文菜单(按住按钮或者EditText弹出) 注意:上下文菜单如何弹出?在注册该菜 ...
- Function 语意学
C++支持三种类型的member functions: static.nonstatic和virtual,每一种类型调用方式都不相同. 一 nostatic members functions 1 调 ...
- QT打开网页 QURL
用QT打开一个网页就是先定义一个QUrl对象url,然后利用QDesktopServices::open(url)即可. 例如: const QUrl url(http://www.baidu.com ...
- iOS设备后台播放音乐方法
iOS设备后台播放音乐方法 1 在设置Capabliites中打开Background Modes,选择Audio And AirPlay 2 在控制viewDidLoad中添加下面代码 AVAudi ...
- cf Perfect Pair
http://codeforces.com/contest/318/problem/C #include <cstdio> #include <cstring> #includ ...
- MySQL常用Json函数
官方文档:JSON Functions Name Description JSON_APPEND() Append data to JSON document JSON_ARRAY() Create ...
- 深入理解Java的protected修饰符
其实Java的protected修饰符,权限定义的很微妙,大致有以下几种: (1)protected控制符用于修饰方法和成员变量: (2)一个类的protected方法或成员变量,在包外是不能通过该类 ...
- 单片微机原理P4:80C51串口与串行总线拓展
0. 串口通讯 0. 串口通讯的数据传输方式:单工(单向传输数据),半双工(非同时双向传输),全双工(同时,双向传输) 1. 根据通信方式的不同又分为同步通讯和异步通讯. 同步通讯:所有设备都使用同一 ...
- hibernate分页查询的各种方法
统计总数: public Integer countAll1() { String hql = "select count(*) from News as news"; List ...