LocalDateTime localDateTime=LocalDateTime.now(); //格式化日期时间类型为字符串 DateTimeFormatter dateTimeFormatter=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); String ss = dateTimeFormatter.format(localDateTime).toString(); System.out.println(ss); //日期时间字符串类型转 LocalDateTime DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); LocalDateTime yy = LocalDateTime.parse("2017-09-28 21:22:33", df); System.out.println(yy); //日期字符串转日期类型 LocalDate localDate=LocalDate.parse("2019-12-10",DateTimeFormatter.ofPattern("yyyy-MM-dd")); System.out.println(localDate.toString()); }