Java Data Type How to - Convert Instant to LocalDateTime


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


/*w ww.  j  a  v a 2  s .co  m*/
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

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

      // convert Instant to LocalDateTime or other similar classes
      LocalDateTime date = LocalDateTime.ofInstant(timestamp,
      System.out.println("Date = " + date);

The code above generates the following result.