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 executionpublic class Edpresso {// main methodpublic static void main(String[] args) {// Calling currentTimeMillis() methodSystem.out.println("Current time:"+ " " + System.currentTimeMillis() + "ms");}}
Explanation
- Line 7:
System.currentTimeMillis()is called for the current time.