Previous code to get the current system time.
You can obtain the system time by checking the time () on the network. If you find any problem, you can only obtain the system time in seconds.
Then I found the following article:
========================================================== ========================================================== ============================================
From http://blog.csdn.net/jefry_xdz/article/details/8072097
I am working on the underlying Android ndk test code. In many cases, I need to obtain the current system's Millisecond Time to accurately analyze the data. The following code is a test on the Android system, therefore, this function code is feasible in the Linux system. I did not test it as to whether VC is feasible or not (it should not work), because sleep in VC and Linux C is quite different. I will share the current system time in milliseconds for C/C ++.
- It is easy to get the current system in milliseconds using Java:
[Java]
View plaincopyprint?
- Public Static VoidMain (string [] ARGs ){
- System. Out. println ("Java program:" + system. currenttimemillis ());
- }
public static void main(String[] args){ System.out.println("java program :" + System.currentTimeMillis()); }
- C/C ++ is a little more complex. It requires the help of timeval. For the detailed description of timeval, you only need to Google it to understand it. I will not introduce it any more:
[CPP]
View plaincopyprint?
- # Include <stdio. h>
- # Include <sys/time. h>
- LongGetcurrenttime ()
- {
- StructTimeval TV;
- Gettimeofday (& TV, null );
- ReturnTV. TV _sec * 1000 + TV. TV _usec/1000;
- }
- IntMain ()
- {
- Printf ("C/C ++ program: % LD \ n", getcurrenttime ());
- Return0;
- }
#include <stdio.h> #include <sys/time.h> long getCurrentTime() { struct timeval tv; gettimeofday(&tv,NULL); return tv.tv_sec * 1000 + tv.tv_usec / 1000; } int main() { printf("c/c++ program:%ld\n",getCurrentTime()); return 0; }
Test results:
C/C ++ program: 1350354127212
Java program: 1350354129299