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 中 APILocalDateTime 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中APIDate from = Date.from(instant1);System.out.println(from);}
