直接上代码
/**
* 将LocalDateTime 转换成Date
* @param localDateTime
* @return
*/
public static Date localDateTimeToDate(LocalDateTime localDateTime){
final ZoneId zoneId = ZoneId.systemDefault();
final ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId);
return Date.from(zonedDateTime.toInstant());
}
/**
* 将 Date 转换成 LocalDateTime
* @param date
* @return
*/
public static LocalDateTime dateToLocalDateTime(Date date){
final ZoneId zoneId = ZoneId.systemDefault();
final Instant instant = date.toInstant();
return instant.atZone(zoneId).toLocalDateTime();
}