C++读系统时间,且读出毫秒的方法[VC和GCC]

来源:互联网 发布:tb淘宝旺旺 编辑:程序博客网 时间:2024/05/18 03:11

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

<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(662) | 评论(0) | 转发(2) |
0

上一篇:收藏摄影作品

下一篇:IDEA算法c语言实现

相关热门文章
  • test123
  • 编写安全代码——小心有符号数...
  • 使用openssl api进行加密解密...
  • 一段自己打印自己的c程序...
  • sql relay的c++接口
  • linux dhcp peizhi roc
  • 关于Unix文件的软链接
  • 求教这个命令什么意思,我是新...
  • sed -e "/grep/d" 是什么意思...
  • 谁能够帮我解决LINUX 2.6 10...
给主人留下些什么吧!~~
评论热议
0 0