A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3resource.com/java-tutorial/util/date/java_date_toinstant.php below:

Website Navigation


Java Date toinstant() Method - w3resource

Java Date.toinstant()MethodLast update on November 13 2023 12:36:51 (UTC/GMT +8 hours) 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




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4