Here's the time () function, but returns seconds, not milliseconds. If you need more precision, you can use platform-specific functions such as Windows GetSystemTimeAsFileTime () or * nix gettimeofday () .
If you really do not care about the date and time, but just want the time interval between two events, for example:
long time1 = System.currentTimeMillis(); // ... do something that takes a while ... long time2 = System.currentTimeMillis(); long elapsedMS = time2 - time1;
then the equivalent of C clock () . On Windows, GetTickCount () is more often used for this purpose.
source share