Java Calendar toInstant() Method

The toInstant() method of the Calendar class is used to convert the current object to an instant, and this instant represents same time as the current calendar object.

Syntax

Parameter

Does not accept any parameter.

Returns

Returns the instant representing same time.

Throws

Does not throw Exception.

Example 1

Output:

 Past calendar : Sat Aug 18 12:07:13 PDT 2018
calendar after using toInstant() : 2018-08-18T19:07:13.206Z

Example 2

Output:

cal Sat Aug 18 12:14:53 PDT 2018
cal.toInstant() : 2022-11-12T02:20:53.084Z