Java Date.toinstant()Method
public Instant toInstant()
The toinstant() method is used to convert Date object to an Instant. The conversion creates an Instant that represents the same point on the time-line as this Date.
Package: java.util
Java Platform: Java SE 8
Syntax:
toInstant()
Return Value:
an instant representing the same point on the time-line as this Date object.
Return Value Type:
Example: Java Date.toInstant() Method
import java.util.Date;
import java.time.Instant;
public class Main {
public static void main(String[] args) {
// create a date
Date date = new Date(2012, 2, 2);
// Converts the said Date object to an Instant.
Instant i = date.toInstant();
System.out.println(i);
}
}
Output:
3912-03-02T00:00:00Z
Java Code Editor:
Previous:setTime Method
Next:toString Method
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/java-tutorial/util/date/java_date_toinstant.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics