Java Data Type How to - Convert java.util.Date to Instant








Question

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

Answer

import java.time.Instant;
// ww w .j  a v a  2s  .com
public class Main {

  public static void main(String[] args) {
    java.util.Date currentDate = new java.util.Date();
    Instant i = currentDate.toInstant();
    System.out.println(i);

  }
}

The code above generates the following result.