Java Convert Calendar to Instant

Tags: Java Calendar Java Instant

In this Java core tutorial we learn how to convert a java.util.Calendar object into a java.time.Instant object in Java programming language.

How to convert Calendar to Instant

In Java we can use the Calendar.toInstant() method to get Instant object of a given Calendar object as the following Java program.

ConvertCalendarToInstantExample1.java

import java.time.Instant;
import java.util.Calendar;

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

        // Convert Calendar to Instant
        Instant instant = calendar.toInstant();

        System.out.println(instant);
    }
}
The output as below.
2022-04-16T06:45:48.057Z

Happy Coding 😊

Java Convert Calendar to Date

Java Convert Calendar to Milliseconds

Java Convert Calendar to String

Java Calendar by Examples

Java Calendar using Calendar.Builder by Examples