Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6054466
  • 博文数量: 2759
  • 博客积分: 1021
  • 博客等级: 中士
  • 技术积分: 4091
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-11 14:14
文章分类

全部博文(2759)

文章存档

2019年(1)

2017年(84)

2016年(196)

2015年(204)

2014年(636)

2013年(1176)

2012年(463)

分类:

2012-12-20 13:49:35


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

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