String日期与LocalDateTime互转

String strDate="2018-01-03 18:06:36";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

//String日期转LocalDateTime
LocalDateTime d = LocalDateTime.parse(strDate,formatter);
System.out.println(d);

//LocalDateTime转String日期
String sd = formatter.format(d);
System.out.println(sd);

 

posted on 2018-01-03 18:11  秦岭过客  阅读(136)  评论(0编辑  收藏  举报