Calculating Elapsed Time

long start = System.currentTimeMillis();
											// do some other stuff...
											long end = System.currentTimeMillis();
											long elapsedTime = end – start;

By calculating elapsed time, we can determine how long it takes to do something or how long a process takes to complete. To do this, we use the System.currentTimeMillis() method to obtain the current time in milliseconds. We use this method at the start and end of the task we want to get the elapsed time for, and then take the difference in times. The actual value that is returned by the System.currentTimeMillis() method is the time since Janauary 1, 00:00:00, 1970 in milliseconds.

JDK 1.5 adds a nanoTime() method to the System class, which allows you to get even more precise timing, ...

Get Java™ Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.