Java Data Type How to - Convert Date to Instant








Question

We would like to know how to convert Date to Instant.

Answer

/*  w w  w .j  a va  2  s .c o m*/
import java.time.Instant;
import java.util.Date;

public class Main {
    public static void main(String[] args) {
      // Date to Instant
      Instant timestamp = new Date().toInstant();
      System.out.println(timestamp);
    }
}

The code above generates the following result.