The toInstant() method of Date class in Java is used to convert a Date object to an Instant object. An Instant is created during the conversion which is used to represent the same point on the timeline as this Date.
public Instant toInstant()
Parameters: The method does not take any parameters.
Return Value: The method returns an Instant representing the same point on the timeline as this Date.
Below programs illustrate the use of toInstant() method in Java:
Original Date: Wed Jan 30 06:01:46 UTC 2019 Instant: 2019-01-30T06:01:46.730Z
Original Date: Fri Jul 12 06:01:49 UTC 1996 Instant: 1996-07-12T06:01:49.766Z
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.