To convert Java Date
to Instant
, use the toInstant()
method from Date
.
import java.time.Instant; import java.util.Date; public class Main { public static void main(String[] args) { Date dt = new Date(); System.out.println("Date: " + dt); /*w w w . j av a 2s . c o m*/ Instant in = dt.toInstant(); System.out.println("Instant: " + in); } }