Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1687885
  • 博文数量: 347
  • 博客积分: 9328
  • 博客等级: 中将
  • 技术积分: 2680
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-29 23:45
文章分类

全部博文(347)

文章存档

2016年(1)

2013年(4)

2012年(207)

2011年(85)

2010年(50)

分类: C/C++

2012-12-19 10:51:13


  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. }

阅读(1964) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~