We would like to know how to convert java.util.Date to java.time.LocalDateTime.
import java.time.LocalDateTime; import java.time.ZoneId; import java.util.Date; //from www. ja va 2 s . c om public class Main { public static void main(String[] args) { Date date = new Date(); LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); System.out.println(localDateTime); } }
The code above generates the following result.