Home » Java programming language

Java System class currentTimeMillis() method with example

System class currentTimeMillis() method: Here, we are going to learn about the currentTimeMillis() method of System class with its syntax and example.
Submitted by Preeti Jain, on September 15, 2019

System class currentTimeMillis() method

  • currentTimeMillis() method is available in java.lang package.
  • currentTimeMillis() method is used to return the current time in milliseconds.
  • currentTimeMillis() method is static, it is accessible with the class name too.
  • currentTimeMillis() method does not throw any exception.

Syntax:

    public static long currentTimeMillis ();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is long, it returns the current time in milliseconds.

Example:

// Java program to demonstrate the example of 
// currentTimeMillis () method of System Class

public class currentTimeMillis {
    public static void main(String[] args) {
        System.out.print("The current time is: ");
        System.out.println(System.currentTimeMillis() + " ms");
    }
}

Output

E:\Programs>javac currentTimeMillis.java
E:\Programs>java currentTimeMillis
The current time is: 1568565897586 ms


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.