Get Time in Milliseconds Using Java Calendar



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
Updated on: 2020-06-27T09:02:34+05:30

781 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements