1 public static void main(String[] args) { 2 DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); 3 LocalDateTime time = LocalDateTime.now(); 4 String localTime = df.format(time); 5 LocalDateTime ldt = LocalDateTime.parse("2018-01-12 17:07:05",df); 6 System.out.println("LocalDateTime转成String类型的时间:"+localTime); 7 System.out.println("String类型的时间转成LocalDateTime:"+ldt); 8 }
LocalDateTime转成String类型的时间:2018-01-12 17:36:52
String类型的时间转成LocalDateTime:2018-01-12T17:07:05