Java Convert Calendar to Milliseconds

Tags: Java Calendar

In this Java core tutorial we learn how to convert a java.util.Calendar object into milliseconds value.

How to convert Calendar to Milliseconds

In Java we can use the Calendar.getTimeInMillis() method to get the milliseconds value of a Calendar object as following Java code.

ConvertCalendarToMillisecondsExample1.java

import java.util.Calendar;

public class ConvertCalendarToMillisecondsExample1 {
    public static void main(String... args) {
        Calendar calendar = Calendar.getInstance();

        // Convert Calendar to milliseconds
        long milliseconds = calendar.getTimeInMillis();

        System.out.println(milliseconds);
    }
}
The output as below.
1650091071321

Happy Coding 😊

Java Convert Calendar to Date

Java Convert Calendar to Instant

Java Convert Calendar to String

Java Calendar by Examples

Java Calendar using Calendar.Builder by Examples