What is currentTimeMillis() in Java?

Overview

The static currentTimeMillis() method from the java.lang.System class is used to get the current program execution time in milliseconds. The millisecond will be returned as a unit of time. The value in milliseconds also depends on the underlying operating system and system architecture.

Syntax


static long currentTimeMillis()

Parameters

The function does not take any parameter.

Return value

milliseconds: It returns the time difference between the current time and midnight on January 1, 1970 UTC in milliseconds.

Note: Milliseconds are represented as ms.

Example

// Program to check currentTimeMillis() method execution
public class Edpresso {
// main method
public static void main(String[] args) {
// Calling currentTimeMillis() method
System.out.println("Current time:"
+ " " + System.currentTimeMillis() + "ms");
}
}

Explanation

  • Line 7: System.currentTimeMillis() is called for the current time.

Free Resources