Aug 28

【Code § C++】【例】如何取得当前时间并计算时间差   不指定

felix021 @ 2007-8-28 21:54 [IT » 程序设计] 评论(2) , 引用(0) , 阅读(10372) | Via 本站原创 | |
【Code § C++】【例】如何取得当前时间并计算时间差  
代码如下


#include<iostream>
#include <iomanip>
using namespace std;
#include <windows.h> [separator]

int main()
{

  SYSTEMTIME _time1,_time2;
  float interval;
  GetLocalTime(&_time1);
  /* Codes */
  Sleep(2050);  
  /* Codes */  
  GetLocalTime(&_time2);
  interval=(_time2.wMinute-_time1.wMinute)*60; /*间隔多少分钟*/
  interval+=_time2.wSecond-_time1.wSecond;/*间隔多少秒 */
  interval*=1000;/*转为毫秒*/
  interval+=(_time2.wMilliseconds-_time1.wMilliseconds);/*加上毫秒数*/
  interval/=1000;/*转为秒*/
  printf("The inteval is %f.",interval);

  cout <<"时间间隔是: "<<interval<<"s."<<endl;
  getchar();
  return 0;
}






欢迎扫码关注:




转载请注明出自 ,如是转载文则注明原出处,谢谢:)
RSS订阅地址: https://www.felix021.com/blog/feed.php
份额发
2009-3-30 11:39
你在元旦 0点 前后 看看
felix021 回复于 2009-3-30 17:19
呵呵 好早以前写的了,当时不想考虑这么细节,一般测试能用就行了
Danny
2008-5-1 22:20
恩,很好。
分页: 1/1 第一页 1 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   *非必须
网址   电邮   [注册]