long→LocalDateTime
public LocalDateTime longToLocalDateTime(Long milli) {
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
ZoneId zone = ZoneId.systemDefault();
return LocalDateTime.ofInstant(Instant.ofEpochMilli(milli),zone);
}
Date→LocalDateTime
public LocalDateTime dateToLocalDateTime(Date date) {
Instant instant = date.toInstant();
ZoneId zoneId = ZoneId.systemDefault();
return instant.atZone(zoneId).toLocalDateTime();
}
LocalDateTime →Date
public Date localDateTimeTodate(LocalDateTime localDateTime) {
ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime zdt = localDateTime.atZone(zoneId);
return Date.from(zdt.toInstant());
}