Chinaunix首页 | 论坛 | 博客
  • 博客访问: 233287
  • 博文数量: 127
  • 博客积分: 34
  • 博客等级: 民兵
  • 技术积分: 655
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-03 10:53
文章分类

全部博文(127)

文章存档

2013年(19)

2012年(108)

分类:

2012-12-19 23:14:56


  1. #include <iostream>
  2. #ifdef WIN32
  3. #include <windows.h>
  4. #else
  5. #include <sys/time.h>
  6. #endif

  7. using std::cout;
  8. using std::endl;

  9. long GetMillisecond()
  10. {
  11.     long    lMillisecond = 0L;
  12. #ifdef WIN32
  13.     SYSTEMTIME    st;     // System time structure
  14.     GetSystemTime(&st);     // Get system time
  15.     lMillisecond = st.wMilliseconds;     // Get millisecond
  16. #else
  17.     struct timeval tv;
  18.     gettimeofday(&tv, NULL);     // NULL is only legal value
  19.     lMillisecond = tv.tv_usec / 1000;     // Get Millisecond;
  20. #endif

  21.     return lMillisecond;
  22. }

  23. int main()
  24. {
  25.     int i = 0;     // Counter
  26.     cout<<"Get Millisecond Example by JJ."<<endl;
  27.     cout<<"----------------------------"<<endl;

  28.     for (i = 0; i < 20; ++i)
  29.     {
  30.         cout<<GetMillisecond()<<endl;
  31.         Sleep(100);
  32.     }
  33.     cout<<"----------------------------\nDone!"<<endl;
  34.     return 0;
  35. }

阅读(809) | 评论(0) | 转发(0) |
0

上一篇:寻找第K大的数

下一篇:友元

给主人留下些什么吧!~~