Java Program to convert java.util.Date to ZonedDateTime

Java 8Object Oriented ProgrammingProgramming

Create a Date object −

Date date = new Date();

Now, set the ZonedId to default −

final ZoneId id = ZoneId.systemDefault();

Convert java.util.date to ZonedDateTime −

System.out.println(ZonedDateTime.ofInstant(date.toInstant(), id));

Example

 Live Demo

import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;
public class Demo {
   public static void main(String[] args) {
      Date date = new Date();
      final ZoneId id = ZoneId.systemDefault();
      System.out.println(ZonedDateTime.ofInstant(date.toInstant(), id));
   }
}

Output

2019-04-19T00:37:33.344+05:30[Asia/Calcutta]
raja
Published on 24-Apr-2019 12:30:28
Advertisements