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. IIS大数据请求设置方法

    大并发大数据量请求一般会分为几种情况: 1.大量的用户同时对系统的不同功能页面进行查找,更新操作 2.大量的用户同时对系统的同一个页面,同一个表的大数据量进行查询操作 3.大量的用户同时对系统的同一个 ...

  2. Js 读写cookies

    //写cookies函数 function setCookie(name, value)//两个参数,一个是cookie的名子,一个是值 { var Days = 30; //此 cookie 将被保 ...

  3. Android Broadcast Receiver

    说明 有时候我们在做android系统软件的时候,经常会需要做的事就是开机重新设置上次关机前的状态,当然,我们就会用到这个开机广播: <uses-permission android:name= ...

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

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

  5. LeetCode中有技巧的题需要面试前记得的

    https://leetcode.com/problems/insert-interval/ http://www.cnblogs.com/yxzfscg/p/4459173.html https:/ ...

  6. LeetCode: Binary Tree Level Order Traversal && Binary Tree Zigzag Level Order Traversal

    Title: Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to ...

  7. linux面试题1

    一.填空题:1. 在Linux系统中,以 文件 方式访问设备 .2. Linux内核引导时,从文件 /etc/fstab 中读取要加载的文件系统.3. Linux文件系统中每个文件用 i节点 来标识. ...

  8. 【转】Linux Posix Timer使用

    原文网址:http://blog.csdn.net/hongszh/article/details/8608781 最强大的定时器接口来自POSIX时钟系列,其创建.初始化以及删除一个定时器的行动被分 ...

  9. wap版和pc版的旋转js

    <script type="text/javascript"> var evt = "onorientationchange" in window ...

  10. android view的setVisibility方法值的意思

    android view的setVisibility方法值的意思 有三个值 visibility  One of VISIBLE, INVISIBLE, or GONE. 常量值为0,意思是可见的 常 ...