vc 获取当前时间(2010-02-10 11:34:32)

http://wenku.baidu.com/view/6ade96d049649b6648d7475e.html

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)

//Sleep(500);

long t2= GetTickCount_r();();//程序段结束后取得系统运行时间(ms)

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 获取当前时间 (zhuan)的更多相关文章

  1. vc 获取当前时间

    1.使用CTime类 CString str; //获取系统时间 CTime tm; tm=CTime:: GetCurrentTime_r(); str=tm.Format("现在时间是% ...

  2. VC++ 获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法

    1.使用CTime类(获取系统当前时间,精确到秒) CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();//获取系统日期 str=tm ...

  3. 【VS开发】VC++ 获取系统时间、程序运行时间(精确到秒,毫秒)的五种方法

    1.使用CTime类(获取系统当前时间,精确到秒) CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();//获取系统日期 str=tm ...

  4. VC获取精确时间的做法

    声明:本文章是我整合网上的资料而成的,其中的大部分文字不是我所为的,我所起的作用只是归纳整理并添加我的一些看法.非常感谢引用到的文字的作者的辛勤劳动,所参考的文献在文章最后我已一一列出. 对关注性能的 ...

  5. vc 获取网络时间

    方式1 : #include <WinSock2.h> #include <Windows.h> #pragma comment(lib, "WS2_32" ...

  6. VC中如何获取当前时间(精度达到毫秒级)

    标 题: VC中如何获取当前时间(精度达到毫秒级)作 者: 0xFFFFCCCC时 间: 2013-06-24链 接: http://www.cnblogs.com/Y4ng/p/Millisecon ...

  7. VC++编程中获取系统时间

    <span style="white-space:pre"> </span>总结了在程序中如何获得系统时间的方法 void CGetSystenTimeDl ...

  8. C/C++获取系统时间

    C/C++获取系统时间需要使用Windows API,包含头文件"windows.h". 系统时间的数据类型为SYSTEMTIME,可以在winbase.h中查询到如下定义: ty ...

  9. 获取当前时间并格式化,CTime类

    CTime类,此类应该不是C++标准类库,属于windows封装的关于时间的类库,使用环境应该为 Win32程序,MFC程序,VC++程序 CTime tm = CTime::GetCurrentTi ...

随机推荐

  1. BZOJ_1028_[JSOI2007]_麻将_(模拟+贪心)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1028 同一种花色的牌,序数为\(1,2,...,n\).定义"和了"为手上 ...

  2. parentNode(返回指定节点的父节点。)

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  3. HNOI2008越狱(快速幂)

    快速幂水过,贴一下模版. ; var x,y,n,m:int64; function power(num,times:int64):int64; var temp:int64; begin then ...

  4. javascript倒计时代码

    其实就是用两个时间戳相减,余数转换为日期,就是所剩的年月日时分秒,不过年份-1970 $scope.timerID = null; $scope.timerRunning = false;$scope ...

  5. LeetCode Contains Duplicate II (判断重复元素)

    题意:如果有两个相同的元素,它们之间的距离不超过k,那么返回true,否则false. 思路:用map记录每个出现过的最近的位置,扫一边序列即可.扫到一个元素就判断它在前面什么地方出现过.本题数据有点 ...

  6. (转)Linux: su sudo sudoer

    http://zebralinux.blog.51cto.com/8627088/1369301 日常操作中为了避免一些误操作,更加安全的管理系统,通常使用的用户身份都为普通用户,而非root.当需要 ...

  7. 基于ffmpeg的简单音视频编解码的例子

    近日需要做一个视频转码服务器,对我这样一个在该领域的新手来说却是够我折腾一番,在别人的建议下开始研究开源ffmpeg项目,下面是在代码中看到的一 段例子代码,对我的学习非常有帮助.该例子代码包含音频的 ...

  8. MySQL基础之第13章 MySQL函数

    13.1.数学函数 随机数可能会用到,其他基本无视. 13.2.字符串函数 重点CONCAT(S1,S2….) 13.3.日期和时间函数 一.MySQL 获得当前日期时间 函数 1.1 获得当前日期+ ...

  9. HDU 5734 Acperience

    Acperience Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  10. 【转载】epoll的使用

    select,poll,epoll简介 select select本质上是通过设置或者检查存放fd标志位的数据结构来进行下一步处理.这样所带来的缺点是: 1 单个进程可监视的fd数量被限制 2 需要维 ...