Get time in milliseconds using Java Calendar

Java 8Object Oriented ProgrammingProgramming

Create a Calendar object.

Calendar cal = Calendar.getInstance();

For using above Calendar class, do not forget to import the following package.

import java.util.Calendar;

Now, use the getTimeInMillis() method to get the time in milliseconds.

cal.getTimeInMillis()

The following is the final example.

Example

 Live Demo

import java.util.Calendar;
public class Demo {
   public static void main(String[] args) {
      Calendar cal = Calendar.getInstance();
      System.out.println("Milliseconds =" + cal.getTimeInMillis());
   }
}

Output

Milliseconds =1542636999896
raja
Published on 17-Dec-2018 10:23:34
Advertisements