1、LocalDateTime和string进行转换
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//LocalDateTime转String
String localTime = df.format(time);
//String转localDateTime
LocalDateTime ldt = LocalDateTime.parse("2017-09-28 17:07:05",df);
2、LocalDateTime和Date进行转换
//Date to LocalDateTime
Date todayDate = new Date();
LocalDateTime ldt = todayDate.toInstant()
.atZone( ZoneId.systemDefault() )
.toLocalDateTime();
//LocalDateTime to Date
LocalDateTime localDateTime = LocalDateTime.now();
Date date = Date.from( localDateTime.atZone( ZoneId.systemDefault()).toInstant());
3、Date和String进行转换
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//Date转String
String dateString = formatter.format(new Date());
//String 转Date
String date = "2020-11-26 15:46:22";
Date date = formatter.parse(date);
4、Timestamp和LocalDateTime
Timestamp publishtime = xxxx;
LocalDateTime localDateTime = Instant.ofEpochMilli(publishtime.getTime()).atZone(ZoneOffset.ofHours(8)).toLocalDateTime();