Java : System Time and Calculate Processing Time

System.currentTimeMillis(): Returns the current time in milliseconds. The granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.

System.nanoTime(): Returns the current value of the running Java Virtual Machine’s high-resolution time source, in nanoseconds. This method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time.

These methods are used to calculate processing time or performance of operations , methods and apis.

Processing Time = End Time – Start Time ;

Check below example to calculate processing time :


public class SystemTimeCalculation {

public static void main(String[] args) {
long startTime=System.currentTimeMillis();
long nanoStartTime=System.nanoTime();
int i=0;
long endTime=System.currentTimeMillis();
long nanoEndTime=System.nanoTime();
System.out.println("System Calculate Time:"+(endTime-startTime));
System.out.println("System Calculate Nano Time:"+(nanoEndTime-nanoStartTime));




System Calculate Time:2
System Calculate Nano Time:1888263

This site uses Akismet to reduce spam. Learn how your comment data is processed.