Java System currentTimeMillis() Method
Example
Print the current time in milliseconds:
public class Main {
public static void main(String[] args) {
long now = System.currentTimeMillis();
System.out.println(now);
}
}
Note: The output is different each time you run the program.
Definition and Usage
The currentTimeMillis() method returns the current time as a number of milliseconds (thousandths of a second) since January 1, 1970, 00:00:00 UTC.
It is often used to measure how long some code takes: read the time before and after the code, and subtract the first value from the second.
Tip: To measure short times more exactly, use the nanoTime() method.
Syntax
public static long currentTimeMillis()
Parameter Values
None.
Technical Details
| Returns: | A long value, the number of milliseconds since January 1, 1970, 00:00:00 UTC. |
|---|
Related Pages
❮ System Methods