- #include <iostream>
- #ifdef WIN32
- #include <windows.h>
- #else
- #include <sys/time.h>
- #endif
- using std::cout;
- using std::endl;
- long GetMillisecond()
- {
- long lMillisecond = 0L;
- #ifdef WIN32
- SYSTEMTIME st; // System time structure
- GetSystemTime(&st); // Get system time
- lMillisecond = st.wMilliseconds; // Get millisecond
- #else
- struct timeval tv;
- gettimeofday(&tv, NULL); // NULL is only legal value
- lMillisecond = tv.tv_usec / 1000; // Get Millisecond;
- #endif
- return lMillisecond;
- }
- int main()
- {
- int i = 0; // Counter
- cout<<"Get Millisecond Example by JJ."<<endl;
- cout<<"----------------------------"<<endl;
- for (i = 0; i < 20; ++i)
- {
- cout<<GetMillisecond()<<endl;
- Sleep(100);
- }
- cout<<"----------------------------
Done!"<<endl;
- return 0;
- }
相关热门文章
给主人留下些什么吧!~~
评论热议