How to convert Date to Instant and Instant to Date in Java

Views: 720   

java.time.Instant introduced in Java8 and it represents instantaneous point on the time-line.

Converting Date to Instant

Date date = new Date();
Instant instant = date.toInstant();

Converting Instant to Date

Instant instant = Instant.now();
Date date = Date.from(instant);
On By