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()); }