GregorianCalendar toInstant() in Java

toInstant(): This method is available in java.util.GregorianCalendar class of Java.

Syntax:

Instant java.util.Calendar.toInstant()

This method converts this object to an Instant. 

Parameters: NA 

Returns: the instant representing the same point on the timeline.

Exceptions: NA

Approach

Java

import java.util.GregorianCalendar;

public class GregorianCalendartoInstant {
    public static void main(String[] args) {

        GregorianCalendar cal = new GregorianCalendar();

        System.out.println(cal.toInstant());
    }
}

Output:

2022-02-18T15:51:30.513Z


No comments:

Post a Comment