public static void main(String[] args) {
//日期格式化
LocalDateTime dateTime = LocalDateTime.now();
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
String time = dateTime.format(dtf);
System.out.println(time);
System.out.println("------------------Date==》LocalDateTime------------------");
//获取当前时间
Date date = new Date();
//转成时间戳
Instant instant = date.toInstant();
//时间戳 + 时区
//使用LocalDateTime 中 API
LocalDateTime dateTime1 = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
System.out.println(dateTime1);
System.out.println("------------------LocalDateTime==》Date------------------");
LocalDateTime dateTime2 = LocalDateTime.now();
//获得LocalDateTime时间戳
Instant instant1 = dateTime2.atZone(ZoneId.systemDefault()).toInstant();
//使用Date中API
Date from = Date.from(instant1);
System.out.println(from);
}